* {
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --green: #6aaa64;
    --yellow: #c9b458;
    --gray: #787c7e;
    --black: #121213;
    --border: #3a3a3c;
    --red: #ef4444;
    --accent: #00d4ff;
    --purple: #a855f7;
    --blue-btn: #2563eb;
    --orange-btn: #f59e0b;
}

body {
    background-color: #050505;
    color: white;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
    transition: background-color 0.15s ease;
}

body.glitch-flash {
    background-color: #300a0a !important;
}

#app-wrapper {
    width: 100%;
    max-width: 480px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(4px, 1.5dvh, 12px) 10px;
    background-color: var(--black);
    justify-content: space-between;
}

header {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    min-height: clamp(48px, 6dvh, 60px);
    margin: 2px 0;
    padding: 2px 0;
}

.header-title-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: calc(100% - 76px);
    text-align: center;
}

.game-tagline {
    margin: 1px 0 0;
    font-family: 'Special Elite', cursive;
    font-size: clamp(0.62rem, 1.75dvh, 0.82rem);
    color: #8a8a90;
    letter-spacing: 0.04em;
    line-height: 1.2;
}

/* Persistent link from the daily game to Vs Friend mode */
.vs-link {
    display: inline-block;
    margin-top: 5px;
    padding: 4px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: #fff;
    font-size: clamp(0.65rem, 1.6dvh, 0.78rem);
    font-weight: 700;
    font-family: sans-serif;
    letter-spacing: 0.08em;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
    box-shadow: 0 1px 6px rgba(106, 170, 100, 0.35);
}

.vs-link:hover {
    opacity: 0.88;
    text-decoration: none;
}


/* End-of-day CTA into Vs mode — replaces the disabled controls when the daily
   case is finished (sits in the .controls grid row, no layout shift). */
.vs-cta {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    text-align: center;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: #000;
    text-decoration: none;
    font-weight: 700;
    font-size: clamp(0.78rem, 2dvh, 0.95rem);
    padding: 0 14px;
    min-height: clamp(48px, 7dvh, 60px);
    border-radius: 8px;
}

.vs-cta[hidden] {
    display: none !important;
}

/* Very short screens (e.g. iPhone SE): trim the keyboard a touch so the
   10-row board + keyboard + the Vs Friend link all clear. */
@media (max-height: 700px) {
    #tracker .letter-key {
        height: clamp(36px, 5dvh, 46px);
    }
    /* On very short screens keep the VS link as compact text to reclaim space. */
    .vs-link {
        padding: 2px 8px;
        font-size: 0.65rem;
        margin-top: 3px;
        box-shadow: none;
    }
}

h1 {
    margin: 0;
    font-family: 'Special Elite', cursive;
    font-size: clamp(1.2rem, 3.5dvh, 1.8rem);
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    display: flex;
    gap: 2px;
}

.title-letter {
    display: inline-block;
}

.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    border: 1px solid #555;
    color: #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background: #222;
    font-size: 1.25rem;
}

.help-btn {
    position: absolute;
    left: 0px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: white;
    border: none;
    font-weight: 900;
}

.stats-btn {
    position: absolute;
    right: 0px;
}

.stats-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #1e1e20;
    padding: clamp(3px, 0.8vh, 6px);
    border-radius: 10px;
    margin-bottom: 2px;
    border: 1px solid var(--border);
    width: 100%;
    flex-shrink: 0;
}

.info-bar {
    display: flex;
    justify-content: space-around;
    width: 100%;
    font-size: clamp(0.68rem, 2vw, 0.8rem);
    color: #aaa;
    margin-bottom: 6px;
    gap: 4px;
}

#case-num {
    white-space: nowrap;
    font-weight: 600;
    color: #ddd;
}

/* Truth check pip indicators — shared by solo and PvP */
.pvp-pip-label {
    color: #888;
    margin-right: 5px;
    font-size: clamp(0.65rem, 1.8vw, 0.78rem);
}

.pvp-pip {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1.5px solid #666;
    background-color: transparent;
    margin: 0 2px;
    vertical-align: middle;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.pvp-pip.filled {
    background-color: var(--orange-btn);
    border-color: var(--orange-btn);
}

#grid-container {
    display: flex;
    flex-direction: column !important;
    width: 100%;
    justify-content: center;
    flex-grow: 1;
    align-items: center;
    overflow: visible;
    margin-bottom: 5px;
    min-height: 0;
}

#col-main {
    gap: clamp(2px, 0.35dvh, 5px) !important;
}

.word-row {
    display: flex !important;
    flex-direction: row !important;
    gap: clamp(2px, 0.5dvw, 4px);
    flex-shrink: 0;
    justify-content: center;
}

.tile {
    width: clamp(28px, 4.5dvh, 54px);
    min-width: 28px;
    min-height: 28px;
    max-width: 54px;
    height: auto;
    aspect-ratio: 1 / 1;
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.95rem, 3.2dvh, 1.8rem);
    font-weight: bold;
    text-transform: uppercase;
    position: relative;
    cursor: pointer;
    border-radius: 4px;
    background-color: #151517;
}

.correct {
    background-color: var(--green);
    border-color: var(--green);
}

.present {
    background-color: var(--yellow);
    border-color: var(--yellow);
}

.absent {
    background-color: var(--gray);
    border-color: var(--gray);
}

/* Tile flip-reveal animation for solo mode */
@keyframes solo-reveal {
    0%   { transform: rotateX(-90deg); opacity: 0.6; }
    100% { transform: rotateX(0deg);   opacity: 1; }
}

.tile.solo-reveal {
    animation: solo-reveal 0.45s ease forwards;
    backface-visibility: hidden;
}

@keyframes truth-ring-appear {
    from { transform: scale(0.2); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

@keyframes lie-stroke-draw {
    from { clip-path: inset(0 100% 0 0); }
    to   { clip-path: inset(0 0% 0 0); }
}

@media (prefers-reduced-motion: reduce) {
    .tile.solo-reveal  { animation: none; }
    .tile.verified-truth::after { animation: none; }
    .tile.verified-lie::after   { animation: none; }
}

.tile.verified-truth::after {
    content: '';
    position: absolute;
    inset: 6%;
    box-sizing: border-box;
    border: 2.5px solid rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    pointer-events: none;
    animation: truth-ring-appear 250ms ease-out forwards;
}

/* Diagonal white stroke (top-left → bottom-right, backslash) for a confirmed lie. */
.tile.verified-lie::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 142%;
    height: 3px;
    background: rgba(255, 255, 255, 0.98);
    transform: translate(-50%, -50%) rotate(45deg);
    transform-origin: center;
    border-radius: 2px;
    box-shadow:
        0 0 3px rgba(0, 0, 0, 0.9),
        0 0 1px rgba(0, 0, 0, 0.85);
    pointer-events: none;
    z-index: 3;
    animation: lie-stroke-draw 300ms ease-out forwards;
}

/* USER CLUE MARKERS (Deduction Note UI) */
.tile.user-true::before {
    content: '';
    position: absolute;
    width: 94%;
    height: 94%;
    border: 3.5px solid rgba(0, 0, 0, 0.85);
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}

.tile.user-false::before {
    content: '\\';
    position: absolute;
    color: black;
    font-size: clamp(2rem, 7vw, 2.6rem);
    display: flex;
    justify-content: center;
    align-items: center;
    transform: translateY(-2px);
    font-weight: 400;
    pointer-events: none;
    z-index: 2;
}

.tile.user-ignore::before {
    content: '—';
    position: absolute;
    color: black;
    font-size: clamp(1.1rem, 4.5vw, 1.5rem);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    pointer-events: none;
    z-index: 2;
}

#tracker {
    display: flex;
    flex-direction: column;
    gap: clamp(3px, 0.6dvh, 6px);
    width: 100%;
    padding: 0 4px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 5px;
    width: 100%;
}

.letter-key {
    background-color: #2d2d30;
    border: 1px solid var(--border);
    color: white;
    text-align: center;
    height: clamp(42px, 5dvh, 52px);
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    font-size: clamp(0.85rem, 2dvh, 1.1rem);
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.letter-key.known {
    background-color: var(--green);
}

.letter-key.eliminated {
    background-color: var(--red);
}

.letter-key.special {
    background-color: #444;
    font-size: 0.85rem;
    flex: 1.6;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    padding: 0 4px 10px 4px;
    flex-shrink: 0;
}

button {
    padding: clamp(9px, 1.4dvh, 16px);
    border: none;
    cursor: pointer;
    font-weight: bold;
    border-radius: 8px;
    color: white;
    font-size: clamp(0.9rem, 2dvh, 1.1rem);
}

#submit-btn {
    background-color: var(--blue-btn);
}

#truth-btn {
    background-color: var(--orange-btn);
}

#truth-btn.truth-mode {
    background-color: #b45309;
    border: 1px solid white;
    box-shadow: 0 0 10px var(--orange-btn);
}

#truth-btn:disabled {
    background-color: #3a3a3c !important;
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    border: none;
}

.modal {
    display: none;
    position: fixed;
    z-index: 200;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
}

/* Compact how-to modal so it fits on one screen without a scrollbar */
#helpModal .modal-content {
    padding: 14px 18px;
}

#helpModal h2 {
    margin: 0 0 10px 0 !important;
    font-size: 1.1rem;
}

#helpModal .help-section p,
#helpModal .help-section > p {
    margin: 4px 0;
    font-size: 0.85rem;
    line-height: 1.35;
}

#helpModal .help-section h3 {
    margin-bottom: 4px !important;
}

#helpModal hr {
    margin: 8px 0 !important;
}

#helpModal .word-row {
    margin: 3px 0 1px 0 !important;
}

/* On very short screens collapse the tile demo rows completely so the text
   alone carries the meaning — this removes ~80px on iPhone SE */
@media (max-height: 700px) {
    #helpModal .word-row {
        display: none !important;
    }
    #helpModal hr {
        margin: 4px 0 !important;
    }
    #helpModal .modal-content {
        padding: 8px 16px !important;
        margin: 2px auto !important;
    }
    #helpModal h2 {
        font-size: 1rem !important;
        margin: 0 0 4px 0 !important;
    }
    #helpModal .help-section p,
    #helpModal .help-section > p {
        font-size: 0.82rem !important;
    }
    #helpModal button {
        margin-top: 5px !important;
        padding: 9px !important;
    }
}

#helpModal .modal-kb-preview {
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 0.85rem;
}

#helpModal button {
    margin-top: 8px !important;
    padding: 10px !important;
}

.modal-content {
    background-color: #1e1e20;
    margin: 2dvh auto;
    padding: 16px 20px;
    border-radius: 12px;
    width: 92%;
    max-width: 460px;
    text-align: left;
    border: 1px solid var(--border);
    max-height: 94dvh;
    overflow-y: auto;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 15px 0;
    text-align: center;
}

.stat-box {
    background: #151517;
    padding: 8px 4px;
    border-radius: 6px;
    border: 1px solid #2a2a2c;
}

/* STATISTICS & DISTRIBUTION CHART */
.stat-box .num {
    font-size: 1.3rem;
    font-weight: bold;
    display: block;
    color: white;
}

.stat-box .label {
    font-size: 0.55rem;
    text-transform: uppercase;
    color: #aaa;
    font-weight: 600;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

.time-box-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 15px;
    text-align: center;
}

#guess-dist-chart {
    display: flex;
    flex-direction: column !important;
    gap: 5px;
    width: 100%;
    margin-top: 10px;
}

.dist-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    width: 100%;
}

.dist-bar-container span {
    width: 14px;
    text-align: right;
    font-weight: bold;
    color: #aaa;
}

.dist-bar {
    background: #3a3a3c;
    height: 18px;
    display: flex;
    align-items: center;
    padding-left: 8px;
    min-width: 22px;
    border-radius: 3px;
    color: white;
    font-weight: bold;
    font-size: 0.75rem;
}

.dist-bar.winner {
    background: var(--green);
}

#shareModal {
    z-index: 210;
}

.share-preview-box {
    background: #151517;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    text-align: left;
    max-height: 45vh;
    overflow-y: auto;
}

#share-preview-text {
    margin: 0 0 12px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 0.95rem;
    color: #fff;
    line-height: 1.4;
}

.share-url-bubble {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.18), rgba(168, 85, 247, 0.15));
    border: 1px solid rgba(0, 212, 255, 0.45);
    color: var(--accent);
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-decoration: none;
}

#message {
    margin: 1px 0;
    font-weight: bold;
    text-align: center;
    font-size: clamp(0.9rem, 2.5dvh, 1.2rem);
    color: white;
    font-family: 'Special Elite', monospace;
    min-height: 24px;
}

.section-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    margin: 15px 0 8px 0;
    color: #aaa;
    font-family: sans-serif;
    letter-spacing: 0.5px;
    text-align: left;
}

.world-record-card {
    background: linear-gradient(135deg, #1a2a1a 0%, #151517 55%, #1e1a10 100%);
    border: 1px solid #3d5a2e;
    border-radius: 10px;
    padding: 16px 14px;
    text-align: center;
    box-shadow: 0 0 18px rgba(106, 170, 100, 0.15);
}

.world-record-callsign {
    font-family: 'Special Elite', cursive;
    font-size: clamp(2rem, 8vw, 2.6rem);
    letter-spacing: 0.35em;
    color: var(--green);
    margin-bottom: 6px;
}

.world-record-time {
    font-family: sans-serif;
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    font-variant-numeric: tabular-nums;
    color: #fff;
    font-weight: bold;
}

.world-record-sub {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #888;
    font-family: sans-serif;
}

/* "Also Today ▾" inline button inside the WR card */
.wr-lb-toggle {
    margin-top: 12px;
    font-size: 0.8rem;
    font-family: sans-serif;
    color: var(--green);
    cursor: pointer;
    user-select: none;
    letter-spacing: 0.04em;
}

.wr-lb-toggle:hover {
    text-decoration: underline;
}

/* Leaderboard rows tightened for the compact inline layout */
.wr-leaderboard {
    margin-top: 8px;
    text-align: left;
}

.wr-leaderboard li {
    padding: 6px 8px;
    margin-bottom: 4px;
    background: rgba(0, 0, 0, 0.25);
    border-color: rgba(255, 255, 255, 0.05);
}

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

.leaderboard-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: #151517;
    border-radius: 6px;
    border: 1px solid #2a2a2c;
    font-family: sans-serif;
    font-size: 0.9rem;
}

.leaderboard-list .lb-rank {
    color: #888;
    min-width: 1.2em;
}

.leaderboard-list .lb-name {
    flex: 1;
    font-weight: bold;
    letter-spacing: 0.15em;
    color: var(--accent);
}

.leaderboard-list .lb-time {
    font-variant-numeric: tabular-nums;
    color: #ccc;
}

.leaderboard-loading,
.leaderboard-empty {
    justify-content: center;
    color: #888 !important;
    font-weight: normal !important;
    letter-spacing: 0 !important;
}

.feedback-container {
    margin-top: 20px;
    font-size: 0.85rem;
    text-align: center;
}

.feedback-container a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent);
    opacity: 0.8;
    transition: opacity 0.2s;
}

.feedback-container a:hover {
    opacity: 1;
}