* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #1a1a1a;
    --surface: #2a2a2a;
    --surface-light: #3a3a3a;
    --text: #e0e0e0;
    --text-dim: #888;
    --accent: #4a9eff;
    --accent-hover: #6ab0ff;
    --danger: #ff6b6b;
    --warning: #ffa94d;
    --success: #69db7c;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

body {
    overflow: hidden;
}

.screen {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Setup Screen */
#setup-screen {
    position: fixed;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.setup-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
    padding-bottom: 4rem;
}

.setup-container h1 {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
}

.setup-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    overflow: hidden;
}

.setup-section h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-dim);
}

input[type="text"] {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text);
    margin-bottom: 1rem;
}

input[type="text"].small {
    width: 80px;
}

input[type="text"]:focus {
    outline: 2px solid var(--accent);
}

.add-player-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.add-player-form input[type="text"] {
    flex: 1;
    min-width: 100px;
    margin-bottom: 0;
}

.role-toggles {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.role-toggles label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-light);
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.role-toggles input:checked + label,
.role-toggles label:has(input:checked) {
    background: var(--accent);
    color: #fff;
}

.roster-list {
    margin: 1rem 0;
    max-height: 300px;
    overflow-y: auto;
}

.roster-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--surface-light);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.roster-item .player-number {
    font-weight: bold;
    min-width: 60px;
    margin-right: 0.75rem;
}

.roster-item .player-name {
    flex: 1;
}

.roster-item .player-roles {
    color: var(--text-dim);
}

.roster-item .delete-btn {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
}

.setup-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

/* Branding */
.branding {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-light);
    color: var(--text-dim);
    font-size: 0.8rem;
}

.branding-logo {
    height: 120px;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.branding a:hover .branding-logo {
    opacity: 1;
}

/* Saved rosters */
.saved-rosters {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--surface-light);
}

.saved-rosters h3 {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

.saved-roster-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--surface-light);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.saved-roster-item .delete-btn {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.load-roster-section {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.load-roster-section select {
    flex: 1;
    padding: 0.75rem;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text);
}

.save-roster-section {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-light);
}

.save-roster-section input {
    flex: 1;
    margin-bottom: 0;
}

/* Wall setup */
.wall-setup {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-light);
    overflow: hidden;
}

.wall-setup h3 {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

.wall-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    max-width: 100%;
    overflow: hidden;
}

.wall-group {
    border-radius: 8px;
    padding: 0.5rem;
}

.wall-header {
    font-weight: bold;
    text-align: center;
    margin-bottom: 0.5rem;
    padding: 0.3rem;
    border-radius: 4px;
    color: var(--accent);
}

.wall-slots {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.wall-slot {
    padding: 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--surface-light);
    border-radius: 4px;
    background: transparent;
    color: var(--text);
}

.wall-slot.locked {
    background: var(--danger);
    color: var(--text);
    opacity: 0.8;
    cursor: not-allowed;
}

.wall-slot.needs-replacement {
    background: var(--warning);
    color: var(--bg);
    font-weight: bold;
    border: 2px solid var(--danger);
}

/* Wall selector (game screen) */
.wall-selector {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.wall-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: bold;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    background: var(--surface-light);
    color: var(--text);
}

.wall-btn.available {
    border-color: #fff;
    opacity: 1;
}

.wall-btn.selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff;
}

.wall-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.wall-btn.on-track {
    opacity: 0.4;
}

.wall-btn:not(:disabled):hover {
    opacity: 0.85;
    border-color: #fff;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-small {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: var(--surface-light);
    color: var(--text-dim);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    background: var(--surface-light);
    color: var(--text);
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
}

.period-jam {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.period-indicator {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-dim);
}

.period-indicator span {
    color: var(--warning);
    font-size: 1.5rem;
}

.jam-counter {
    font-size: 2rem;
    font-weight: bold;
}

.jam-counter span {
    color: var(--accent);
    font-size: 2.5rem;
}

.game-name {
    font-size: 1.1rem;
    color: var(--text-dim);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.header-actions .btn-undo {
    background: var(--accent);
    color: #fff;
    padding: 0.6rem 1.25rem;
    font-size: 1rem;
}

.header-actions .btn-secondary-small {
    background: transparent;
    color: var(--text-dim);
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border: 1px solid var(--surface-light);
}

.header-actions .btn-warning-small {
    background: var(--warning);
    color: #1a1a1a;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border: none;
}

/* Lineup Panels */
.lineup-panels {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.lineup-panel {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.lineup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.lineup-panel h2 {
    font-size: 1rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0;
    text-align: center;
}

.wall-name-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
    margin-left: 0.5rem;
    text-transform: none;
    letter-spacing: 0;
}

.btn-star-pass {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: #ffd43b;
    color: #1a1a1a;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-star-pass:hover {
    background: #fab005;
}

.btn-star-pass:active {
    transform: scale(0.95);
}

.btn-star-pass:disabled {
    background: var(--surface-light);
    color: var(--text-dim);
    cursor: not-allowed;
}


.lineup-slots {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.slot {
    position: relative;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 10px;
    min-height: 60px;
    cursor: pointer;
    transition: transform 0.1s;
    background: var(--surface);
}

.slot:active {
    transform: scale(0.98);
}

.role-icon {
    font-size: 1.5rem;
    width: 40px;
    text-align: center;
}

.player-info {
    flex: 1;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-info .number {
    font-weight: bold;
}

.btn-penalty {
    margin-left: auto;
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-penalty:hover {
    background: #ff5252;
}

.btn-penalty:active {
    transform: scale(0.95);
}

.slot.empty {
    opacity: 0.5;
}

.slot.in-box {
    background: var(--danger);
    border-left-color: #ff3333;
}

.slot.in-box .player-info {
    color: #fff;
}

.box-badge {
    display: inline-block;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 0.5rem;
    text-transform: uppercase;
}

.slot.blocked {
    opacity: 0.6;
    background: var(--surface);
    border-left-color: var(--danger);
    cursor: not-allowed;
}

.slot.blocked:active {
    transform: none;
}

.blocked-label {
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: bold;
}

.slot.returning-from-box {
    background: var(--surface);
    border-left-color: var(--warning);
    border-style: dashed;
}

.returning-label {
    color: var(--warning);
    font-size: 0.9rem;
    font-weight: bold;
}

/* Box toggle slots in current lineup */
.slot.box-toggle {
    cursor: pointer;
}

.slot.box-toggle:hover {
    filter: brightness(1.1);
}

.slot.box-toggle:active {
    transform: scale(0.98);
}

.player-name {
    flex: 1;
}

.box-action {
    margin-left: auto;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.box-action.penalize {
    background: var(--danger);
    color: #fff;
}

.box-action.release {
    background: var(--success);
    color: #1a1a1a;
}

.slot.unavailable-player {
    background: var(--surface);
    border-left-color: var(--warning);
    opacity: 0.8;
}

.unavailable-badge {
    margin-left: auto;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    background: var(--warning);
    color: #1a1a1a;
}

.slot.jammer {
    border-left: 4px solid #ffd43b;
}

.slot.pivot {
    border-left: 4px solid #748ffc;
}

.slot.blocker {
    border-left: 4px solid #868e96;
}

/* Divider with Start Button */
.panel-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--bg);
}

.btn-start {
    padding: 1.25rem 2.5rem;
    font-size: 1.3rem;
    font-weight: bold;
    background: var(--success);
    color: #1a1a1a;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}

.btn-start:hover {
    background: #5fd478;
}

.btn-start:active {
    transform: scale(0.95);
}

.btn-start.btn-stop {
    background: var(--danger);
}

.btn-start.btn-stop:hover {
    background: #ff5252;
}

/* Bench Panel */
.bench-panel {
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--surface-light);
}

.bench-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.bench-panel h3 {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0;
}

.branding-inline {
    font-size: 0.75rem;
    color: var(--text-dim);
    opacity: 0.5;
    text-decoration: none;
    transition: opacity 0.2s;
}

.branding-inline:hover {
    opacity: 0.8;
}

.bench-players {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.bench-player {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--surface-light);
    border-radius: 8px;
    white-space: nowrap;
    cursor: pointer;
    min-width: fit-content;
    font-size: 1rem;
}

.bench-player .roles {
    font-size: 0.85rem;
}

.bench-player.unavailable {
    opacity: 0.4;
}

.bench-player.in_box {
    border: 2px solid var(--danger);
}

.bench-player.injured {
    border: 2px solid var(--warning);
}

.bench-player.fouled_out {
    border: 2px solid #868e96;
    text-decoration: line-through;
}

.bench-player.queued {
    border: 2px solid #f59f00;
}

.bench-player.resting {
    border: 2px solid #748ffc;
}

/* Drag and drop */
.bench-player[draggable="true"] {
    cursor: grab;
}

.bench-player[draggable="true"]:active {
    cursor: grabbing;
}

.bench-player.dragging {
    opacity: 0.4;
}

.slot.drop-target {
    border: 2px dashed var(--accent);
}

.slot.drag-over {
    background: var(--accent);
    border: 2px solid var(--accent);
}

/* Status badges */
.status-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.status-badge.in-box {
    background: var(--danger);
    color: #fff;
}

.status-badge.queued {
    background: #f59f00;
    color: #1a1a1a;
}

.status-badge.injured {
    background: var(--warning);
    color: #1a1a1a;
}

.status-badge.resting {
    background: #748ffc;
    color: #fff;
}

.status-badge.fouled-out {
    background: #868e96;
    color: #fff;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
}

.modal-content h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    text-align: center;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.btn-status {
    padding: 1rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.btn-status:hover {
    background: var(--accent);
}

.btn-status.active {
    background: var(--accent);
}

.modal-position-info {
    text-align: center;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    background: var(--surface-light);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.substitute-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-light);
}

.substitute-section h4 {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.substitute-section select {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text);
}

/* Player Picker Modal */
.picker-content {
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.picker-players {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-height: 50vh;
}

.picker-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface-light);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s;
}

.picker-player:hover {
    background: var(--accent);
}

.picker-player:active {
    transform: scale(0.98);
}

.picker-player .number {
    font-weight: bold;
    min-width: 50px;
}

.picker-player .name {
    flex: 1;
}

.picker-player .location {
    font-size: 0.8rem;
    color: var(--text-dim);
    padding: 0.2rem 0.5rem;
    background: var(--surface);
    border-radius: 4px;
}

.picker-player .roles {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.picker-player.on-track .location {
    background: var(--accent);
    color: #fff;
}

.picker-player.in-wall .location {
    background: var(--warning);
    color: #1a1a1a;
}

.picker-player.selected {
    background: var(--accent);
    border: 2px solid var(--accent-hover);
}

.btn-warning-full {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    background: var(--warning);
    color: #1a1a1a;
    cursor: pointer;
    margin-bottom: 0.5rem;
}

.btn-warning-full:hover {
    filter: brightness(1.1);
}

/* Landscape optimization */
@media (orientation: landscape) and (max-height: 500px) {
    .slot {
        padding: 0.5rem 1rem;
        min-height: 45px;
    }
    
    .role-icon {
        font-size: 1.2rem;
    }
    
    .player-info {
        font-size: 1rem;
    }
    
    .bench-panel {
        padding: 0.5rem 1rem;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}
