/* ================================================================
   QUANTUM TIC-TAC-TOE — Design System
   Identidade Visual: Quantum Universe Expo / Bobbie Goods
   ================================================================ */

/* --- RESET --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- TOKENS --- */
:root {
    --bg:          #f0ede8;
    --surface:     #ffffff;
    --surface-alt: #e8e5e0;
    --ink:         #111111;
    --ink-mid:     #444444;
    --ink-muted:   #888888;

    /* Functional (mantidas) */
    --cx:       #06b6d4;
    --cx-dark:  #0e7490;
    --cx-light: #e0f7fa;
    --co:       #d946ef;
    --co-dark:  #a21caf;
    --co-light: #fce7ff;
    --cc:       #f59e0b;   /* collapse */
    --cc-dark:  #b45309;
    --cc-light: #fef3c7;
    --cw:       #22c55e;   /* win */
    --cw-dark:  #15803d;
    --cw-light: #dcfce7;

    /* Sketch shadows */
    --sh:    4px 4px 0 var(--ink);
    --sh-sm: 2px 2px 0 var(--ink);
    --sh-lg: 6px 6px 0 var(--ink);
    --bd:    3px solid var(--ink);
    --bd-tk: 4px solid var(--ink);

    /* Fonts */
    --f-title: 'Bangers', cursive;
    --f-body:  'Special Elite', serif;
    --f-ui:    'Nunito', sans-serif;

    /* Cell size — tablet friendly */
    --cell: clamp(95px, 25vw, 135px);
}

/* --- BASE --- */
html, body { height: 100%; }

body {
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(0,0,0,0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.035) 1px, transparent 1px);
    background-size: 28px 28px;
    color: var(--ink);
    font-family: var(--f-ui);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px 32px;
    overflow-x: hidden;
}

/* --- APP WRAPPER (Controla a largura de todos os filhos igualmente) --- */
#app {
    width: 100%;
    max-width: 465px; /* Tamanho exato do tabuleiro em telas grandes */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ================================================================
   HEADER
   ================================================================ */
.app-header {
    width: 100%;
    margin-bottom: 18px;
    text-align: center;
}

.expo-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 20px 12px;
    background: var(--surface);
    border: var(--bd-tk);
    box-shadow: var(--sh);
    margin-bottom: 10px;
}

.expo-tag {
    font-family: var(--f-ui);
    font-weight: 900;
    font-size: 0.55rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.expo-name {
    font-family: var(--f-title);
    font-size: clamp(2.2rem, 9vw, 3.8rem);
    line-height: 0.92;
    letter-spacing: 0.04em;
    color: var(--ink);
}

.expo-sub {
    width: 100%;
    padding-top: 8px;
    border-top: 2px solid var(--ink);
    font-family: var(--f-body);
    font-size: 0.6rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink-mid);
}

.game-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.game-title {
    font-family: var(--f-title);
    font-size: clamp(1.3rem, 4.5vw, 2rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.title-accent {
    width: 36px;
    height: 3px;
    background: var(--ink);
}

/* ================================================================
   TURN INDICATOR
   ================================================================ */
.turn-indicator {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface);
    border: var(--bd-tk);
    box-shadow: var(--sh);
    margin-bottom: 14px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.turn-indicator.state-x {
    border-color: var(--cx-dark);
    box-shadow: 4px 4px 0 var(--cx-dark);
}
.turn-indicator.state-o {
    border-color: var(--co-dark);
    box-shadow: 4px 4px 0 var(--co-dark);
}
.turn-indicator.state-collapse {
    border-color: var(--cc-dark);
    box-shadow: 4px 4px 0 var(--cc-dark);
    background: var(--cc-light);
}
.turn-indicator.state-win {
    border-color: var(--cw-dark);
    box-shadow: 4px 4px 0 var(--cw-dark);
    background: var(--cw-light);
}

/* Collapse ring: mantém cor do jogador mas adiciona anel âmbar animado */
.turn-indicator.state-collapse-ring {
    animation: collapse-ring-pulse 0.9s ease-in-out infinite;
}
@keyframes collapse-ring-pulse {
    0%,100% { outline: 3px dashed transparent;     outline-offset: 2px; }
    50%      { outline: 3px dashed var(--cc-dark);  outline-offset: 4px; }
}

/* Badge */
.player-badge {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--f-title);
    font-size: 2.2rem;
    border: 3px solid var(--ink);
    box-shadow: var(--sh-sm);
    transition: background 0.3s, color 0.3s;
}
.badge-x { background: var(--cx);  color: #fff; border-color: var(--cx-dark); }
.badge-o { background: var(--co);  color: #fff; border-color: var(--co-dark); }
.badge-collapse {
    background: var(--cc); color: #fff; border-color: var(--cc-dark);
    animation: badge-pulse 0.9s ease-in-out infinite;
}
.badge-win { background: var(--cw); color: #fff; border-color: var(--cw-dark); }

/* Anel âmbar pulsante sobre o badge do jogador durante colapso */
.badge-collapse-pulse {
    box-shadow: 0 0 0 3px var(--cc), 0 0 0 5px var(--cc-dark), var(--sh-sm);
    animation: badge-collapse-ring 0.85s ease-in-out infinite;
}
@keyframes badge-collapse-ring {
    0%,100% { box-shadow: 0 0 0 3px var(--cc),   0 0 0 5px var(--cc-dark), var(--sh-sm); }
    50%      { box-shadow: 0 0 0 6px var(--cc),   0 0 0 9px var(--cc-dark), var(--sh-sm); }
}

@keyframes badge-pulse {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}

/* Turn info text */
.turn-info { flex: 1; min-width: 0; }

.turn-label {
    font-weight: 900;
    font-size: 0.58rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 2px;
}

.turn-message {
    font-weight: 800;
    font-size: clamp(0.8rem, 2.5vw, 0.95rem);
    line-height: 1.3;
    color: var(--ink);
}

/* Turn counter */
.turn-counter {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-left: 2px solid var(--ink);
    padding-left: 12px;
    flex-shrink: 0;
}
.turn-counter-label {
    font-weight: 900;
    font-size: 0.5rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.turn-counter-num {
    font-family: var(--f-title);
    font-size: 2.4rem;
    line-height: 1;
    color: var(--ink);
}

/* Flash animation on turn change */
@keyframes turn-flash {
    0%   { transform: scale(1); }
    35%  { transform: scale(1.03); }
    70%  { transform: scale(0.98); }
    100% { transform: scale(1); }
}
.turn-indicator.just-changed {
    animation: turn-flash 0.45s ease-out;
}

/* ================================================================
   BOARD
   ================================================================ */
.board-wrapper {
    width: 100%;
    padding: 18px;
    background: var(--surface);
    border: var(--bd-tk);
    box-shadow: var(--sh-lg);
    margin-bottom: 16px;
    position: relative;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(3, var(--cell));
    grid-template-rows:    repeat(3, var(--cell));
    gap: 8px;
    justify-content: center;
}

/* ================================================================
   CELL
   ================================================================ */
.cell {
    width:  var(--cell);
    height: var(--cell);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    background: var(--bg);
    border: var(--bd-tk);
    box-shadow: var(--sh-sm);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

.cell:active:not(.cell-classical) {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.cell-empty:hover, .cell-quantum:hover {
    background: var(--surface);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 var(--ink);
}

.cell-classical {
    cursor: default;
    background: var(--surface);
}

.cell-selected-x {
    border-color: var(--cx-dark);
    background: var(--cx-light);
    box-shadow: 4px 4px 0 var(--cx-dark);
}

.cell-selected-o {
    border-color: var(--co-dark);
    background: var(--co-light);
    box-shadow: 4px 4px 0 var(--co-dark);
}

.cell-cycle {
    border-color: var(--cc-dark);
    background: var(--cc-light);
    box-shadow: 4px 4px 0 var(--cc-dark);
    animation: cycle-pulse 0.8s ease-in-out infinite;
    cursor: pointer;
}

@keyframes cycle-pulse {
    0%,100% { transform: scale(1);    box-shadow: 4px 4px 0 var(--cc-dark); }
    50%      { transform: scale(1.05); box-shadow: 6px 6px 0 var(--cc-dark); }
}

/* ================================================================
   MARK CONTENT (CSS-drawn X and O)
   ================================================================ */
.mark-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* X — two crossing bars */
.mark-x {
    position: relative;
    width: 58%;
    height: 58%;
}
.mark-x::before,
.mark-x::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 100%;
    height: 18%;
    background: var(--cx);
    border: 2px solid var(--cx-dark);
    border-radius: 3px;
}
.mark-x::before { transform: rotate(45deg); }
.mark-x::after  { transform: rotate(-45deg); }

/* O — ring */
.mark-o {
    width: 56%;
    height: 56%;
    border-radius: 50%;
    border: clamp(7px, 1.8vw, 11px) solid var(--co);
    outline: 2.5px solid var(--co-dark);
}

/* Glow on choice collapse */
.cell-choice .mark-x { filter: drop-shadow(0 0 6px var(--cx)); }
.cell-choice .mark-o { filter: drop-shadow(0 0 6px var(--co)); }

/* Forced icon */
.forced-icon {
    position: absolute;
    top: 4px;
    right: 5px;
    color: var(--ink-muted);
    opacity: 0.6;
}

/* ================================================================
   QUANTUM MARKERS
   ================================================================ */
.quantum-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    width: 100%;
    height: 100%;
    padding: 6px;
    align-content: center;
    justify-items: center;
}

.q-marker {
    font-family: var(--f-title);
    font-size: clamp(0.75rem, 2.8vw, 1.05rem);
    letter-spacing: 0.03em;
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: 1px;
}
.q-marker.qx { color: var(--cx-dark); }
.q-marker.qo { color: var(--co-dark); }
.q-marker sub { font-size: 0.62em; opacity: 0.85; }

/* ================================================================
   BUTTONS
   ================================================================ */
.btn-row {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-bottom: 16px;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px 12px;
    font-family: var(--f-title);
    font-size: 1.15rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    border: var(--bd-tk);
    box-shadow: var(--sh);
    background: var(--surface);
    color: var(--ink);
    transition: transform 0.1s, box-shadow 0.1s;
    -webkit-tap-highlight-color: transparent;
    min-height: 52px;
}

.btn:hover  { transform: translate(-1px,-1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px);  box-shadow: 2px 2px 0 var(--ink); }

.btn-primary {
    background: var(--ink);
    color: #fff;
}
.btn-primary:hover  { box-shadow: 5px 5px 0 var(--ink-mid); }
.btn-primary:active { box-shadow: 2px 2px 0 var(--ink-mid); }

/* Botão compacto para ícone (fullscreen) */
.btn-icon {
    flex: 0 0 auto;
    width: 52px;
    padding: 0;
}

/* ================================================================
   MODAL
   ================================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17,17,17,0.75);
    animation: fade-in 0.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    background: var(--surface);
    border: var(--bd-tk);
    box-shadow: var(--sh-lg);
    max-width: 460px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    padding: 22px;
    animation: slide-up 0.25s ease;
}

@keyframes slide-up {
    from { transform: translateY(18px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: var(--bd-tk);
}

.modal-title {
    font-family: var(--f-title);
    font-size: 2rem;
    letter-spacing: 0.06em;
}

.btn-close {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: var(--bd);
    box-shadow: var(--sh-sm);
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.btn-close:active { transform: translate(2px,2px); box-shadow: none; }

.rule-block {
    margin-bottom: 14px;
    padding: 14px;
    border: var(--bd);
    box-shadow: var(--sh-sm);
    background: var(--bg);
}

.rule-block h3 {
    font-family: var(--f-title);
    font-size: 1.15rem;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rule-block p {
    font-family: var(--f-body);
    font-size: 0.82rem;
    line-height: 1.65;
    color: var(--ink-mid);
}

.rule-quote {
    margin-top: 10px;
    padding: 8px 12px;
    border-left: 4px solid var(--cc);
    background: var(--cc-light);
    font-family: var(--f-body);
    font-size: 0.78rem;
    font-style: italic;
    color: #78350f;
}

.rule-x { color: var(--cx-dark); }
.rule-o { color: var(--co-dark); }
.rule-c { color: var(--cc-dark); }

.modal-footer {
    margin-top: 20px;
    padding-top: 14px;
    border-top: var(--bd);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--f-title);
    font-size: 1.05rem;
    letter-spacing: 0.08em;
    color: var(--cw-dark);
}
