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

:root {
  --bg:        oklch(10% 0.02 260);
  --surface:   oklch(14% 0.025 260);
  --surface-2: oklch(19% 0.03  260);
  --surface-3: oklch(24% 0.035 260);

  --sistema:     oklch(72% 0.22 250);
  --sistema-dim: oklch(48% 0.14 250);

  --player:     oklch(82% 0.17 75);
  --player-dim: oklch(55% 0.11 75);

  --win:  oklch(72% 0.2  145);
  --loss: oklch(65% 0.24 22);
  --draw: oklch(62% 0.09 260);

  --text:       oklch(93% 0.015 260);
  --text-muted: oklch(52% 0.06  260);
  --text-faint: oklch(34% 0.04  260);

  --border:        oklch(22% 0.035 260);
  --border-subtle: oklch(16% 0.025 260);

  --r:    14px;
  --r-sm:  8px;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100svh;
  background-image: radial-gradient(oklch(20% 0.03 260) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ── Screens ──────────────────────────────────────────────── */

.screen { display: none; min-height: 100svh; }
.screen.active { display: flex; }

/* ── Welcome ──────────────────────────────────────────────── */

#screen-welcome {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(2rem, 6vw, 4rem) clamp(1.25rem, 4vw, 2.5rem);
  position: relative;
  overflow: hidden;
}

#screen-welcome::before {
  content: '';
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(700px, 120vw);
  height: min(700px, 120vw);
  background: radial-gradient(ellipse, oklch(16% 0.08 260 / 0.7) 0%, transparent 65%);
  pointer-events: none;
}

.welcome-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 440px;
}

.welcome-eyebrow {
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--sistema);
  margin-bottom: 2.25rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.welcome-eyebrow::before,
.welcome-eyebrow::after {
  content: '';
  flex: 0 0 28px;
  height: 1px;
  background: var(--sistema-dim);
}

.welcome-headline {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: clamp(3rem, 13vw, 6rem);
  line-height: 0.92;
  text-align: center;
  letter-spacing: -0.025em;
  color: var(--text);
  margin-bottom: 0.75rem;
}
.welcome-headline em {
  font-style: normal;
  color: var(--sistema);
}

.welcome-sub {
  font-size: clamp(0.83rem, 2.4vw, 0.96rem);
  color: var(--text-muted);
  text-align: center;
  line-height: 1.75;
  font-weight: 300;
  max-width: 34ch;
  margin-bottom: 3rem;
}

.welcome-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.name-input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 1.1rem 1.25rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  appearance: none;
  -webkit-appearance: none;
}
.name-input::placeholder { color: var(--text-faint); }
.name-input:focus { border-color: var(--sistema-dim); }

.btn-start {
  width: 100%;
  padding: 1.1rem;
  background: var(--sistema);
  color: var(--bg);
  border: none;
  border-radius: var(--r);
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  touch-action: manipulation;
}
.btn-start:hover:not(:disabled) { opacity: 0.85; }
.btn-start:active:not(:disabled) { transform: scale(0.98); }
.btn-start:disabled { opacity: 0.3; cursor: default; }

.welcome-footer {
  margin-top: 2rem;
  font-size: 0.7rem;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.7;
  max-width: 36ch;
}

/* ── Error box ────────────────────────────────────────────── */

.error-box {
  width: 100%;
  font-size: 0.8rem;
  color: var(--loss);
  padding: 0.5rem 0;
  text-align: center;
  min-height: 1.5rem;
}

/* ── Game Screen ──────────────────────────────────────────── */

#screen-game { flex-direction: column; }

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100svh;
}
@media (min-width: 840px) {
  .game-layout { grid-template-columns: 1fr 290px; }
}

.game-main {
  display: flex;
  flex-direction: column;
  gap: clamp(0.875rem, 2.5vw, 1.5rem);
  padding: clamp(1.1rem, 4vw, 2rem);
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--player);
}

.topbar-round {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
}

.score-pill {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  overflow: hidden;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.score-seg        { padding: 0.3rem 0.85rem; }
.score-seg.p      { color: var(--player); }
.score-seg.s      { color: var(--sistema); }
.score-div        { width: 1px; height: 20px; background: var(--border); }

.btn-dl-mobile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  transition: border-color 0.2s, color 0.2s;
}
.btn-dl-mobile:hover { border-color: var(--player-dim); color: var(--player); }
@media (min-width: 840px) { .btn-dl-mobile { display: none; } }

/* Influence box */
.influence-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.2rem 1.4rem 1.2rem 1.65rem;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  position: relative;
  overflow: hidden;
  transition: opacity 0.3s;
}
.influence-box::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 3px; height: 100%;
  background: var(--sistema);
  transition: background 0.3s;
}
.influence-box.silent           { opacity: 0.55; }
.influence-box.silent::before   { background: var(--border); }
.influence-box.loading::before  { background: var(--text-faint); }

.influence-who {
  font-family: 'Syne', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--sistema);
  transition: color 0.3s;
}
.influence-box.silent  .influence-who { color: var(--text-faint); }
.influence-box.loading .influence-who { color: var(--text-faint); }

.influence-msg {
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: clamp(0.95rem, 3vw, 1.15rem);
  line-height: 1.35;
  color: var(--text);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
.influence-msg.anim { animation: msgIn 0.3s ease-out; }

/* Choices */
.choice-label {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.5rem, 2vw, 0.875rem);
}

.btn-choice {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: clamp(1rem, 3.5vw, 1.75rem) 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.btn-choice:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--player-dim);
}
.btn-choice:active:not(:disabled) { transform: scale(0.94); }
.btn-choice:focus-visible          { border-color: var(--sistema); }
.btn-choice.selected {
  background: oklch(82% 0.17 75 / 0.08);
  border-color: var(--player);
}
.btn-choice:disabled { opacity: 0.42; cursor: default; }

.choice-emoji {
  font-size: clamp(1.75rem, 5.5vw, 2.5rem);
  line-height: 1;
  pointer-events: none;
  transition: transform 0.15s;
}
.btn-choice:hover:not(:disabled) .choice-emoji { transform: scale(1.08); }

.choice-text {
  font-family: 'Syne', sans-serif;
  font-size: clamp(0.62rem, 2vw, 0.72rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  pointer-events: none;
  transition: color 0.15s;
}
.btn-choice:hover:not(:disabled) .choice-text { color: var(--text); }
.btn-choice.selected               .choice-text { color: var(--player); }

/* Result area */
.result-area {
  display: none;
  flex-direction: column;
  gap: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.4rem;
}
@keyframes resultIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result-area.visible {
  display: flex;
  animation: resultIn 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.result-versus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
}
.result-entity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.result-entity-label {
  font-family: 'Syne', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.result-entity-icon   { font-size: 2.4rem; line-height: 1; }
.result-entity-scelta {
  font-family: 'Syne', sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.result-vs-sep {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  color: var(--border);
}

.result-outcome { text-align: center; }
.result-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  letter-spacing: -0.01em;
}
.result-title.win  { color: var(--win); }
.result-title.loss { color: var(--loss); }
.result-title.draw { color: var(--draw); }
.result-comment {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  font-weight: 300;
  font-style: italic;
}

.btn-next {
  width: 100%;
  padding: 0.9rem;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  touch-action: manipulation;
}
.btn-next:hover {
  border-color: var(--sistema-dim);
  color: var(--text);
  background: var(--surface-2);
}
.btn-next:disabled { opacity: 0.4; cursor: default; }

/* Stats strip */
.stats-strip {
  display: flex;
  gap: 1.5rem;
  padding-top: 0.25rem;
  flex-wrap: wrap;
  margin-top: auto;
}
.stat-item {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}
.stat-item strong {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.04em;
}
.stat-item.wr  strong { color: var(--win); }
.stat-item.dr  strong { color: var(--draw); }
.stat-item.tot strong { color: var(--text-muted); }

/* ── Sidebar ──────────────────────────────────────────────── */

.game-sidebar { display: none; }
@media (min-width: 840px) {
  .game-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow: hidden;
  }
}

.sidebar-header {
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.btn-dl {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.38rem 0.75rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-dl:hover { border-color: var(--player-dim); color: var(--player); }

.log-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.log-list::-webkit-scrollbar      { width: 3px; }
.log-list::-webkit-scrollbar-track  { background: transparent; }
.log-list::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 10px; }

.log-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  text-align: center;
}
.log-empty p {
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.7;
}

.log-entry {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.7rem;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 0.45rem;
}
@keyframes logIn {
  from { opacity: 0; transform: translateX(5px); }
  to   { opacity: 1; transform: translateX(0); }
}
.log-entry { animation: logIn 0.22s ease-out; }

.log-num {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.88rem;
  color: var(--text-faint);
  text-align: center;
}
.log-moves {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
}
.log-moves .pm   { color: var(--player);  font-weight: 600; }
.log-moves .sm   { color: var(--sistema); font-weight: 600; }
.log-moves .vsep { color: var(--text-faint); font-size: 0.6rem; }

.log-badge {
  font-family: 'Syne', sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
}
.log-badge.win  { background: oklch(72% 0.2 145 / 0.12); color: var(--win); }
.log-badge.loss { background: oklch(65% 0.24 22  / 0.12); color: var(--loss); }
.log-badge.draw { background: oklch(62% 0.09 260 / 0.1);  color: var(--draw); }

/* ── Flash overlay ────────────────────────────────────────── */
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
}
@keyframes flashAnim {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  100% { opacity: 0; }
}
.flash.go       { animation: flashAnim 0.55s ease-out forwards; }
.flash.win-fl   { background: oklch(72% 0.2 145 / 0.06); }
.flash.loss-fl  { background: oklch(65% 0.24 22  / 0.07); }
