/* ==========================================================================
   Hangman — game-specific styles
   base.css handles tokens, reset, body, Inter font, .chip, focus-visible,
   touch-action, .home-btn, .util-btn(s), .overlay-x, .icon, .icon-btn,
   .visually-hidden, .site-foot, reduced-motion.
   ========================================================================== */

html, body { min-height: 100%; }

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px 32px;
  min-height: 100vh;
}

.app {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  position: relative;
  z-index: 1;
}

.top {
  width: 100%;
  text-align: center;
  padding-left: 52px;
  padding-right: 8px;
}
.top h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel {
  width: 100%;
  background: linear-gradient(145deg, rgba(16, 20, 38, 0.95), #090c18 50%, #05060f 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 26px;
  padding: 22px 22px 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

/* On the menu: hide the page header (the panel has its own title) and centre */
body.on-menu .top { display: none; }
body.on-menu .app {
  justify-content: center;
  min-height: calc(100dvh - 52px);
  margin-top: 0;
}

/* ==========================================================================
   MENU PANEL - site-standard centered menu (ported from darts)
   ========================================================================== */

.menu-panel {
  width: 100%;
  max-width: 430px;
  background: linear-gradient(160deg, #141826, #101321);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 38px 34px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow-soft);
  position: relative;
  z-index: 1;
  animation: menu-entrance 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes menu-entrance {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-logo {
  width: 44px;
  height: 44px;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  color: var(--accent);
  filter: drop-shadow(0 0 12px rgba(138, 124, 255, 0.45));
}

.menu-title {
  font-size: clamp(28px, 5vw, 38px);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.2;
  margin: 0;
}

.menu-form {
  width: 100%;
  display: flex;
  flex-direction: column;
}
.menu-step { display: flex; flex-direction: column; gap: 16px; }
.menu-step:not(.hidden) > * {
  animation: menu-field-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.menu-step:not(.hidden) > *:nth-child(1) { animation-delay: 0.06s; }
.menu-step:not(.hidden) > *:nth-child(2) { animation-delay: 0.12s; }
.menu-step:not(.hidden) > *:nth-child(3) { animation-delay: 0.18s; }
.menu-step:not(.hidden) > *:nth-child(4) { animation-delay: 0.24s; }
.menu-step:not(.hidden) > *:nth-child(5) { animation-delay: 0.3s; }

@keyframes menu-field-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.menu-row-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.menu-start-btn {
  width: 100%;
  background: var(--accent);
  color: #14122b;
  border: none;
  border-radius: var(--radius-pill);
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  margin-top: 4px;
  box-shadow: 0 10px 22px rgba(138, 124, 255, 0.4);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.menu-start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(138, 124, 255, 0.6);
}

.menu-hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  max-width: 380px;
  line-height: 1.5;
}

.menu-stats[hidden] { display: none; }
.menu-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.menu-stats .icon {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Stepped menu: Local/Online choice cards */
.menu-choices { display: flex; gap: 12px; width: 100%; }
.choice-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px 16px;
  background: var(--surface, rgba(255,255,255,0.03));
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 12px);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.choice-card:hover {
  background: var(--surface-hover, rgba(255,255,255,0.09));
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(138, 124, 255, 0.18);
}
.choice-icon { width: 30px; height: 30px; color: var(--accent); margin-bottom: 4px; }
.choice-label { font-size: 15px; font-weight: 700; letter-spacing: 0.03em; }
.choice-desc { font-size: 12px; color: var(--muted); }
.step-back {
  align-self: flex-start;
  background: none; border: none;
  color: var(--muted);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; padding: 2px 4px; margin-bottom: -4px;
  transition: color 0.15s ease;
}
.step-back:hover { color: var(--text); }

/* Menu groups (used by overlays) */
.menu-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.menu-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ==========================================================================
   Segmented controls
   ========================================================================== */
.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  background: transparent;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--muted);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.primary-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  padding: 11px 24px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.primary-btn:hover {
  background: rgba(138, 124, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(138, 124, 255, 0.3);
}
.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.ghost-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* Game-actions row (bottom of setup) */
.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   Overlays (settings / online / result)
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.overlay-card {
  position: relative;
  background: linear-gradient(145deg, #1a1c30, #0d0e1d);
  border: 1px solid rgba(138, 124, 255, 0.3);
  border-radius: 22px;
  padding: 28px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 0 40px rgba(138, 124, 255, 0.2);
  max-width: 340px;
}
.overlay-card h2 {
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.overlay-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.muted { color: var(--muted); font-size: 0.85rem; }

/* ==========================================================================
   ONLINE - create/join overlay + waiting state (ported from darts)
   ========================================================================== */
.online-card { width: 100%; max-width: 340px; }

.online-step {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}
.online-step.hidden { display: none !important; }

.online-main-btn { width: 100%; }

.online-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.online-divider::before,
.online-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.online-join { display: flex; gap: 8px; }
.online-join input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  padding: 9px 14px;
}
.online-join input::placeholder { color: var(--muted); opacity: 0.5; letter-spacing: 0.2em; }
.online-join input:focus { outline: none; border-color: var(--accent); }

.online-config-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.online-wait-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
}
.online-code {
  margin: 0;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.25em;
  text-indent: 0.25em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(138, 124, 255, 0.5);
  cursor: pointer;
  user-select: all;
  text-align: center;
}
.online-wait-sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  animation: hm-wait-pulse 1.6s ease-in-out infinite;
}
@keyframes hm-wait-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

.online-status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.online-status.error { color: #ff5d7a; }
.online-status[hidden] { display: none; }

/* ==========================================================================
   GAME: gallows, word display, keyboard (kept from original hangman)
   ========================================================================== */

/* Setup */
.setup-hint {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
#setupInput {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.2rem;
  padding: 12px 14px;
  text-align: center;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  width: 100%;
  outline: none;
  transition: border-color 0.18s ease;
}
#setupInput:focus { border-color: var(--accent); }
/* Mask characters visually without being a password field
   (text-security is supported in Chromium, Safari, recent Firefox) */
.masked-input {
  -webkit-text-security: disc;
  -moz-text-security: disc;
  text-security: disc;
}
.setup-err {
  color: #ff6b8a;
  font-size: 13px;
  text-align: center;
}

/* Gallows */
.gallows-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.gallows {
  width: 140px;
  height: auto;
  flex-shrink: 0;
  stroke: var(--text);
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
}
.gallows .g-base { stroke: var(--muted); }
.gallows .g-part {
  opacity: 0;
  transition: opacity 0.25s ease;
  stroke: var(--accent);
}
.gallows .g-part.show { opacity: 1; }
.gallows.fail .g-part.show { stroke: #ff6b8a; }

.misses {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.misses #missesValue { color: var(--text); font-size: 1.6rem; font-weight: 800; }

/* Word display */
.word-display {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  min-height: 50px;
  padding: 8px 0;
}
.letter-slot {
  width: 36px;
  height: 44px;
  border-bottom: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  text-transform: uppercase;
  font-family: var(--font-sans);
}
.letter-slot.revealed { color: var(--accent); }
.letter-slot.space { border-bottom: none; width: 20px; }
.letter-slot.missed { color: #ff6b8a; border-bottom-color: #ff6b8a; }

.status {
  text-align: center;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--muted);
  min-height: 1.4em;
}
.status.win { color: var(--accent); font-weight: 700; }
.status.lose { color: #ff6b8a; font-weight: 700; }

/* On-screen keyboard */
.keyboard {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.key {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 15px;
  padding: 10px 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  min-height: 44px;
  text-transform: uppercase;
}
.key:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--accent);
}
.key:disabled { cursor: default; }
.key.hit {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.key.miss {
  background: rgba(255, 107, 138, 0.1);
  color: #ff6b8a;
  border-color: rgba(255, 107, 138, 0.4);
}

@media (max-width: 600px) {
  .panel { padding: 18px 16px 16px; border-radius: 22px; }
  .menu-panel { padding: 30px 22px 24px; }
  .gallows { width: 120px; }
  .letter-slot { width: 28px; height: 36px; font-size: 1.2rem; }
  .word-display { gap: 6px; }
  .keyboard { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .key { font-size: 13px; padding: 11px 0; min-height: 44px; }
}
