/* ============================================
   Daglig Kryssord - Design
   ============================================ */

:root {
    --copper-1: #f4a261;
    --copper-2: #e76f51;
    --copper-3: #b8551e;
    --copper-glow: #ffd8a8;
    --copper-text: #4a1f0a;

    --beige-1: #f5e6c8;
    --beige-2: #e8d5a8;
    --beige-3: #d4b886;
    --beige-text: #5a3e1f;

    --board-bg: #2d4a2a;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1b5e20 0%, #388e3c 50%, #1b5e20 100%);
    min-height: 100vh;
    color: #333;
    padding: 1rem;
}

.container { max-width: 1200px; margin: 0 auto; }

/* ============================================
   Header
   ============================================ */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    margin-bottom: 1rem;
}

.title {
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

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

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
}

.flag-icon { font-size: 1.6rem; line-height: 1; }

/* Spillernavn-chip i headeren, helt til høyre (før hjelp/flagg) */
.player-info-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.9rem;
    height: 44px;
    border-radius: 10px;
    background: rgba(255, 215, 0, 0.18);
    color: #ffd700;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 215, 0, 0.35);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

button.player-info-header {
    cursor: pointer;
    font-family: inherit;
}
button.player-info-header:hover {
    background: rgba(255, 215, 0, 0.28);
}
button.player-info-header:focus {
    outline: 2px solid #ffd700;
    outline-offset: 2px;
}

.player-info-header .player-icon {
    flex-shrink: 0;
    color: #ffd700;
}

.player-info-header .player-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   3-kolonners hovedlayout
   ============================================ */
main {
    display: grid;
    grid-template-columns: 240px 1fr 240px;
    gap: 1rem;
    align-items: start;
}

.word-list-section,
.leaderboard-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.word-list-section h2,
.leaderboard-section h2 {
    font-size: 1.05rem;
    margin-bottom: 0.75rem;
    color: #2e7d32;
    border-bottom: 2px solid #4caf50;
    padding-bottom: 0.5rem;
}

.board-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* ============================================
   Kryssordbrett
   ============================================ */
.crossword-container {
    background: var(--board-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.crossword-grid {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.grid-row {
    display: flex;
    flex-direction: row;
    gap: 3px;
}

.cell {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: bold;
    border-radius: 5px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    user-select: none;
    position: relative;
}

.cell-revealed {
    background: linear-gradient(135deg, var(--copper-1) 0%, var(--copper-2) 50%, var(--copper-3) 100%);
    color: var(--copper-text);
    border: 2px solid var(--copper-3);
    box-shadow:
        inset 0 1px 2px var(--copper-glow),
        inset 0 -2px 4px rgba(74, 31, 10, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.3);
    cursor: default;
    text-shadow: 0 1px 0 rgba(255, 216, 168, 0.4);
}

.revealed-letter {
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.02em;
}

.cell-empty {
    background: linear-gradient(145deg, var(--beige-1) 0%, var(--beige-2) 100%);
    color: var(--beige-text);
    border: 2px solid var(--beige-3);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.5),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}

.cell-empty:hover {
    background: linear-gradient(145deg, #fbf0d8 0%, #f0e0b8 100%);
    transform: translateY(-1px);
}

.cell-empty.cell-selected {
    background: linear-gradient(145deg, #fff7e0 0%, #ffe8b0 100%);
    border-color: #8b6f47;
    box-shadow:
        inset 0 0 0 2px #8b6f47,
        0 2px 6px rgba(139, 111, 71, 0.4);
}

.player-letter {
    color: var(--beige-text);
    font-size: 1.5rem;
    font-weight: 900;
}

/* ============================================
   Alfabet
   ============================================ */
.alphabet-section {
    background: var(--card-bg);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    width: 100%;
    max-width: 500px;
}

.alphabet-section h3 {
    color: #2e7d32;
    margin-bottom: 0.6rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
}

.alphabet {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
}

.letter-btn {
    width: 36px;
    height: 36px;
    border: 2px solid var(--beige-3);
    border-radius: 7px;
    background: linear-gradient(145deg, var(--beige-1), var(--beige-2));
    color: var(--beige-text);
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s ease;
}

.letter-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.letter-btn.selected {
    background: linear-gradient(145deg, var(--copper-1), var(--copper-2));
    color: var(--copper-text);
    border-color: var(--copper-3);
    box-shadow:
        inset 0 1px 2px var(--copper-glow),
        0 0 0 3px rgba(231, 111, 81, 0.3);
    transform: translateY(-2px);
}

/* ============================================
   Handlingsknapper
   ============================================ */
.actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.btn-primary, .btn-secondary {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(145deg, #4caf50, #2e7d32);
    color: white;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(46, 125, 50, 0.5);
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #2e7d32;
    border: 2px solid #4caf50;
}

.btn-secondary:hover {
    background: white;
    transform: translateY(-2px);
}

/* ============================================
   Ordliste (venstre)
   ============================================ */
.words-container {
    max-height: 60vh;
    overflow-y: auto;
}

.word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.4rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.word-item.valid {
    background: #e8f5e9;
    border-left: 4px solid #4caf50;
}

.word-item.pending {
    background: #fbeaea;
    border-left: 4px solid #d99;
    color: #a44;
}

.word-item .word-text { font-weight: 600; }

.word-item .points {
    color: #2e7d32;
    font-weight: bold;
}

.word-item .no-points {
    color: #bbb;
    font-weight: bold;
}

.word-item .penalty {
    color: #f44336;
    font-weight: bold;
}

.total-score {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 2px solid #e0e0e0;
    font-size: 1rem;
    font-weight: bold;
    color: #2e7d32;
    text-align: center;
}
.total-score.negative { color: #b44; border-top-color: #e0b0b0; }

.empty-hint {
    color: rgba(245, 240, 220, 0.5);
    font-style: italic;
    padding: 0.4rem 0.2rem;
    font-size: 0.9rem;
    text-align: center;
}

.scoring-indicator {
    margin-left: 0.4rem;
    color: rgba(245, 240, 220, 0.6);
    font-weight: normal;
}

.total-score > div { margin: 0.2rem 0; }
.penalty-line { color: #f44336 !important; }

/* ============================================
   Leaderboard (høyre)
   ============================================ */
.leaderboard-title {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 2px solid #4caf50;
    background: transparent;
    color: #2e7d32;
    cursor: pointer;
    font: inherit;
    font-size: 1.05rem;
    font-weight: bold;
    margin-bottom: 0.75rem;
    padding: 0 0 0.5rem;
    text-align: left;
}

.leaderboard-title:hover { color: #4caf50; }

.leaderboard-list {
    list-style: none;
    padding: 0;
}

.empty-leaderboard {
    color: rgba(245, 240, 220, 0.55);
    font-style: italic;
    padding: 0.5rem 0.2rem;
    text-align: center;
    font-size: 0.9rem;
}

.leaderboard-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.4rem;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.leaderboard-list li:hover { background: #f5f5f5; }

.leaderboard-list li.me {
    background: linear-gradient(90deg, #fff9c4 0%, transparent 100%);
    font-weight: bold;
    border-left: 3px solid #ffd700;
    padding-left: 0.3rem;
}

.leaderboard-list .rank {
    color: #666;
    min-width: 1.5rem;
    text-align: right;
}

.leaderboard-list .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-list .score {
    color: #2e7d32;
    font-weight: bold;
}

.hint-text {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.5rem;
}

.stats-page {
    grid-template-columns: 240px 1fr 240px;
    justify-content: center;
}

.stats-board-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.date-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.date-navigation button {
    width: 42px;
    height: 36px;
    border: 2px solid #4caf50;
    border-radius: 8px;
    background: white;
    color: #2e7d32;
    cursor: pointer;
    font-size: 1.2rem;
}

.date-navigation button:disabled { opacity: 0.35; cursor: not-allowed; }
.stats-player { cursor: pointer; }
.leaderboard-list li.selected-player { background: #e8f5e9; border-left: 3px solid #4caf50; }
.stats-player-name { color: white; font-size: 1.1rem; }
.stats-cell { cursor: default; }
.stats-cell:hover { transform: none; }
.stats-cell-inactive {
    background: linear-gradient(145deg, #f6e9c9 0%, #ead8ae 100%);
    border-color: var(--beige-3);
}
.stats-cell-fixed {
    background-color: #f2dfb7;
    background-image: repeating-linear-gradient(
        135deg,
        rgba(139, 111, 71, 0.16) 0,
        rgba(139, 111, 71, 0.16) 3px,
        rgba(255, 255, 255, 0.10) 3px,
        rgba(255, 255, 255, 0.10) 8px
    );
}
.stats-message { color: white; font-style: italic; min-height: 1.2rem; }

/* ============================================
   Felles
   ============================================ */
.empty-state {
    text-align: center;
    color: #999;
    padding: 1.5rem 0.5rem;
    font-style: italic;
    font-size: 0.85rem;
}

.empty-state p { margin: 0.3rem 0; }

/* ============================================
   Footer
   ============================================ */
footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    padding: 1rem;
    font-size: 0.85rem;
    margin-top: 1rem;
}

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

.modal {
    background: white;
    padding: 2rem;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal h2 { color: #2e7d32; margin-bottom: 1rem; }
.modal p { margin-bottom: 1rem; line-height: 1.5; color: #555; }
.modal .version-line { color: #888; font-size: 0.85rem; margin-top: -0.5rem; }

/* Velkomst-modal */
.welcome-modal { text-align: center; max-width: 440px; }
.welcome-modal h2 { font-size: 1.6rem; }
.welcome-modal p { font-size: 1.05rem; }

/* ============================================
   Responsiv
   ============================================ */
@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .word-list-section,
    .leaderboard-section {
        position: static;
        max-height: none;
    }
    .word-list-section { order: 2; }
    .board-column,
    .stats-board-column { order: 1; }
    .leaderboard-section { order: 3; }
    .cell { width: 42px; height: 42px; font-size: 1.2rem; }
    .letter-btn { width: 32px; height: 32px; font-size: 0.85rem; }
    .player-info-header { max-width: 160px; font-size: 0.8rem; padding: 0 0.6rem; }
}

@media (max-width: 500px) {
    .cell { width: 38px; height: 38px; font-size: 1.1rem; }
    .title { font-size: 1.2rem; }
    .player-info-header { max-width: 120px; font-size: 0.75rem; }
    .player-info-header .player-icon { display: none; }
}

/* Auth-modal og gjest-tag */
.guest-tag {
    display: inline-block;
    margin-left: 0.4em;
    padding: 0.1em 0.4em;
    font-size: 0.7em;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    vertical-align: middle;
    color: inherit;
    font-weight: 400;
    opacity: 0.85;
}

.modal-close {
    position: absolute;
    top: 0.5em;
    right: 0.8em;
    background: transparent;
    border: 0;
    font-size: 1.8em;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    padding: 0.2em 0.5em;
}
.modal-close:hover { opacity: 0.7; }

.auth-modal {
    position: relative;
    text-align: left;
    max-width: 420px;
    width: 90%;
}
.auth-modal h2 { margin-top: 0.2em; }

.auth-status {
    background: var(--bg-soft, rgba(0, 0, 0, 0.05));
    border-radius: 6px;
    padding: 0.8em 1em;
    margin-bottom: 1em;
    display: flex;
    flex-direction: column;
    gap: 0.4em;
}
.auth-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1em;
    font-size: 0.95em;
}
.auth-label { opacity: 0.7; }

.auth-section { margin: 1em 0; }
.auth-section h3 { margin: 0 0 0.4em; font-size: 1em; opacity: 0.85; }
.auth-hint { font-size: 0.85em; opacity: 0.7; margin: 0 0 0.6em; line-height: 1.4; }

.auth-input-row {
    display: flex;
    gap: 0.4em;
    align-items: stretch;
}
.auth-input {
    flex: 1;
    padding: 0.5em 0.7em;
    border: 1px solid var(--border, rgba(0, 0, 0, 0.2));
    border-radius: 4px;
    font-size: 0.95em;
    background: var(--input-bg, #fff);
    color: inherit;
    min-width: 0;
}
.auth-input:focus { outline: 2px solid var(--accent, #3b82f6); outline-offset: -1px; }
.auth-input:disabled { opacity: 0.6; }

.auth-message {
    margin-top: 0.8em;
    padding: 0.5em 0.7em;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.05);
    font-size: 0.9em;
    line-height: 1.4;
}

.line-bonus {
    font-size: 0.85em;
    opacity: 0.75;
    margin-top: 0.2em;
}

/* Admin-ikon i header */
.admin-icon-header {
    color: var(--accent, #3b82f6);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.stats-btn-header {
    color: inherit;
}
.admin-email {
    font-size: 0.85em;
    opacity: 0.8;
}

/* Klikkbar overskrift */
.clickable-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.3em;
}
.clickable-header:hover { opacity: 0.7; }
.hint-arrow { font-size: 0.7em; }

/* Scoring hjelpetekst */
.scoring-help-modal {
    max-width: 600px;
    width: 90%;
}
.scoring-help-modal h3 {
    margin: 1em 0 0.4em;
    font-size: 1em;
    opacity: 0.85;
}
.scoring-tables {
    display: flex;
    flex-direction: column;
    gap: 1em;
}
.scoring-table-lang strong {
    display: block;
    margin-bottom: 0.3em;
}
.letter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25em;
}
.letter-tile {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 2.8em;
    height: 3em;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.06);
    font-size: 1em;
}
.letter-tile.high { background: rgba(255, 100, 100, 0.15); }
.letter-tile.mid { background: rgba(255, 180, 0, 0.12); }
.letter-tile .letter { font-weight: 600; font-size: 1.1em; }
.letter-tile .pts { font-size: 0.8em; opacity: 0.6; }

/* Admin-panel */
.admin-modal-wide {
    position: relative;
    text-align: left;
    max-width: 820px;
    width: 92%;
    max-height: 88vh;
    overflow-y: auto;
}
.admin-modal-wide h2 { margin-top: 0.2em; }
.admin-modal-wide h3 { margin: 1em 0 0.4em; font-size: 1em; opacity: 0.85; }
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82em;
}
.admin-table th, .admin-table td {
    border: 1px solid var(--border, rgba(0,0,0,0.15));
    padding: 0.35em 0.5em;
    text-align: left;
}
.admin-table th { opacity: 0.7; font-weight: 600; }
.admin-path {
    font-family: monospace;
    font-size: 0.9em;
    opacity: 0.7;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-ua {
    font-size: 0.8em;
    opacity: 0.7;
    white-space: nowrap;
}
.admin-solution {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
}
.admin-solution-lang {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6em;
    align-items: baseline;
    padding: 0.5em 0.7em;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.04);
}
.admin-score {
    font-size: 0.85em;
    opacity: 0.7;
}
.admin-btn {
    color: var(--accent, #3b82f6);
}
