/* ==========================================================================
   style.css — core layout, components and animations.
   Colours live in themes.css; small-screen rules live in responsive.css.
   ========================================================================== */

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

html[data-large-text="on"] { font-size: 18px; }

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
               "Noto Sans", Tahoma, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--color-text);
  background-color: var(--color-background);
  background-image: url("../assets/images/background-pattern.svg");
  background-size: 120px 120px;
  overflow-x: hidden;
}

img { max-width: 100%; }

button {
  font: inherit;
  color: inherit;
}

/* Visible focus for keyboard users — always */
:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Decorative background ornaments ---------- */

.bg-ornaments {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.ornament {
  position: absolute;
  opacity: 0.16;
  filter: drop-shadow(0 0 12px rgba(212, 175, 55, 0.35));
}

[data-theme="light"] .ornament { opacity: 0.12; }

.ornament-lantern-left {
  left: 2%;
  top: 6%;
  width: clamp(48px, 8vw, 90px);
  transform: rotate(-8deg);
}

.ornament-lantern-right {
  right: 2%;
  top: 10%;
  width: clamp(44px, 7vw, 80px);
  transform: rotate(8deg);
}

.ornament-crescent {
  left: 50%;
  top: 3%;
  width: clamp(40px, 6vw, 70px);
  transform: translateX(-50%) rotate(-18deg);
}

/* Gentle float — disabled entirely under reduced motion */
[data-motion="full"] .ornament-lantern-left,
[data-motion="full"] .ornament-lantern-right {
  animation: lanternFloat 9s ease-in-out infinite alternate;
}
[data-motion="full"] .ornament-lantern-right { animation-delay: -4.5s; }

@keyframes lanternFloat {
  from { translate: 0 0; }
  to   { translate: 0 10px; }
}

/* ---------- Header & footer ---------- */

.app-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.tagline {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
}

.icon-btn {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover { background: var(--color-surface-2); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn[aria-pressed="false"] { opacity: 0.65; }

.app-footer {
  position: relative;
  z-index: 1;
  padding: 14px 20px 18px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-muted);
}

.app-footer p { margin: 0; }

/* ---------- Layout ---------- */

.app-main {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
}

.screen { animation: screenIn 0.28s ease-out; }

[data-motion="reduced"] .screen { animation: none; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ---------- Card / panel ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.panel {
  padding: 22px 22px 26px;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}

.panel-sub, .menu-sub {
  margin: 0 0 18px;
  color: var(--color-muted);
  font-size: 0.92rem;
}

.panel-divider {
  height: 3px;
  width: 120px;
  margin: 0 auto 18px;
  border-radius: 2px;
  background:
    radial-gradient(circle at 50% 50%, var(--color-gold) 0 3px, transparent 4px) 50% 50% / 14px 14px no-repeat,
    linear-gradient(90deg, transparent, var(--color-gold), transparent);
  opacity: 0.85;
}

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  padding: 8px 12px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--color-gold);
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
}

.back-link:hover { background: var(--color-surface-2); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:hover { background: var(--color-surface-3); }
.btn:active { transform: scale(0.97); }

.btn.primary {
  background: linear-gradient(160deg, var(--color-gold), #B8912E);
  border-color: #8a6d1f;
  color: #241a05;
  box-shadow: 0 4px 14px rgba(212, 175, 55, 0.25);
}

[data-theme="light"] .btn.primary { color: #1c1403; }

.btn.primary:hover {
  background: linear-gradient(160deg, #E0BF4C, #C29A35);
}

.btn.danger {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.btn.danger:hover { background: rgba(185, 75, 75, 0.12); }

.btn.large { min-height: 54px; font-size: 1.05rem; }

html[data-large-buttons="on"] .btn,
html[data-large-buttons="on"] .menu-btn,
html[data-large-buttons="on"] .icon-btn {
  min-height: 56px;
  font-size: 1.08rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Menu ---------- */

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.menu-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 92px;
  padding: 14px 16px;
  text-align: left;
  border-radius: 14px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.menu-btn:hover {
  background: var(--color-surface-3);
  border-color: var(--color-gold);
}

.menu-btn:active { transform: scale(0.98); }

.menu-btn.primary {
  grid-row: span 1;
  border-color: rgba(212, 175, 55, 0.55);
  background:
    linear-gradient(160deg, rgba(212, 175, 55, 0.14), transparent 55%),
    var(--color-surface-2);
}

.menu-icon { font-size: 1.5rem; line-height: 1; margin-bottom: 4px; }

.menu-label { font-weight: 700; font-size: 1rem; }

.menu-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* Resume banner on the menu */
.resume-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed var(--color-gold);
  background: rgba(212, 175, 55, 0.08);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.resume-banner p { margin: 0; font-size: 0.92rem; }
.resume-banner .row { margin: 0; }

/* ---------- Forms & settings ---------- */

.field { margin: 0 0 18px; }

.field label,
.field legend {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.optional { font-weight: 400; color: var(--color-muted); font-size: 0.82em; }

input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  color: var(--color-text);
  background: var(--color-input);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

input[type="text"]::placeholder { color: var(--color-muted); }

.choice-field {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 14px 14px;
  margin: 0 0 18px;
}

.choice-field legend {
  padding: 0 6px;
  color: var(--color-muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.choice-row, .choice-col { display: flex; gap: 10px; }
.choice-col { flex-direction: column; }

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.choice:hover { border-color: var(--color-gold); }

.choice input {
  width: 20px;
  height: 20px;
  accent-color: var(--color-gold);
  margin: 0;
}

.choice:has(input:checked) {
  border-color: var(--color-gold);
  background: rgba(212, 175, 55, 0.1);
}

.choice small { color: var(--color-muted); }

/* Symbol previews inside choices */
.sym-preview {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--color-board);
  border: 1px solid var(--color-border);
}

.sym-preview svg { width: 72%; height: 72%; display: block; }

.sym-preview.sym-x { color: var(--sym-x); }
.sym-preview.sym-o { color: var(--sym-o); }

/* Settings rows */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--color-border-soft);
  cursor: pointer;
}

.setting-row span:first-child { font-weight: 500; }
.setting-row small { color: var(--color-muted); font-weight: 400; }

.setting-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--color-gold);
  margin: 0;
}

.setting-row select {
  min-height: 44px;
  padding: 8px 10px;
  font: inherit;
  color: var(--color-text);
  background: var(--color-input);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

.volume-wrap { display: flex; align-items: center; gap: 10px; }

input[type="range"] {
  width: 160px;
  accent-color: var(--color-gold);
  height: 32px;
}

output { min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }

.section-title {
  margin: 26px 0 10px;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-gold);
}

.section-title::after {
  content: "";
  display: block;
  width: 46px;
  height: 2px;
  margin-top: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--color-gold), transparent);
  opacity: 0.7;
}

.muted { color: var(--color-muted); }
.settings-note { font-size: 0.85rem; }
.danger-zone { border-top: 1px solid var(--color-border); padding-top: 18px; }

/* ---------- Game screen ---------- */

.game-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.game-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.game-top .back-link { margin-bottom: 0; }

.mode-chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--color-muted);
}

.turn-indicator {
  margin: 0;
  font-size: 1.3rem;
  min-height: 1.8em;
  text-align: center;
}

.turn-indicator.is-winner { color: var(--color-success); }
.turn-indicator.is-ai { color: var(--color-muted); }

.players-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  min-height: 48px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.player-chip.active {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.22);
}

.chip-name { font-weight: 600; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.vs {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted);
}

/* The board */

.board-frame {
  padding: 10px;
  border-radius: 22px;
  background: linear-gradient(160deg, var(--color-frame-1), var(--color-frame-2));
  border: 1px solid var(--color-border);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(78vw, 380px);
  padding: 8px;
  border-radius: 14px;
  background: var(--color-board-lines);
  border: 1px solid var(--color-border);
  touch-action: manipulation;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: var(--color-board);
  cursor: pointer;
  padding: 0;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.cell:not(.filled):hover {
  background: var(--color-board-hover);
}

.cell:not(.filled):active { transform: scale(0.96); }

.cell.filled { cursor: default; }

.cell .sym {
  width: 62%;
  height: 62%;
  display: grid;
  place-items: center;
}

.cell .sym svg { width: 100%; height: 100%; display: block; }

html[data-large-symbols="on"] .cell .sym { width: 80%; height: 80%; }

.cell.sym-x { color: var(--sym-x); }
.cell.sym-o { color: var(--sym-o); }

/* Placement animation */
[data-motion="full"] .cell .sym { animation: symPop 0.22s ease-out; }

@keyframes symPop {
  0%   { transform: scale(0.4); opacity: 0; }
  70%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Winning line highlight */
.cell.win {
  background: var(--color-board-win);
  box-shadow: inset 0 0 0 2px var(--color-gold);
}

[data-motion="full"] .cell.win { animation: winPulse 1.1s ease-in-out 2; }

@keyframes winPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--color-gold); }
  50%      { box-shadow: inset 0 0 0 4px var(--color-gold), 0 0 18px rgba(212, 175, 55, 0.5); }
}

.cell.dim { opacity: 0.45; }

/* Rejected-move feedback (occupied cell) */
.cell.nudge {
  box-shadow: inset 0 0 0 2px var(--color-danger);
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-muted);
  font-size: 0.88rem;
}

/* ---------- Prose screens (how to play, about) ---------- */

.prose h3 { margin: 20px 0 6px; font-size: 1.02rem; color: var(--color-gold); }
.prose p, .prose li { color: var(--color-text); }
.prose ul { padding-left: 22px; margin: 8px 0; }
.prose li { margin: 4px 0; }

/* ---------- Statistics ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.stat-box {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-2);
}

.stat-box .stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-gold);
}

.stat-box .stat-label {
  font-size: 0.78rem;
  color: var(--color-muted);
  letter-spacing: 0.03em;
}

.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.ach {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-2);
  opacity: 0.55;
}

.ach.unlocked {
  opacity: 1;
  border-color: var(--color-gold);
  background: rgba(212, 175, 55, 0.08);
}

.ach-icon { font-size: 1.4rem; line-height: 1; }
.ach-name { display: block; font-weight: 700; font-size: 0.9rem; }
.ach-desc { display: block; font-size: 0.75rem; color: var(--color-muted); }

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--color-border-soft);
  font-size: 0.88rem;
}

.history-item .h-when { color: var(--color-muted); font-size: 0.8rem; }
.history-item .h-what { font-weight: 600; }
.history-item .h-how { color: var(--color-muted); font-size: 0.8rem; }

.history-item .result-win { color: var(--color-success); font-weight: 700; }
.history-item .result-loss { color: var(--color-danger); font-weight: 700; }
.history-item .result-draw { color: var(--color-muted); font-weight: 700; }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 20, 18, 0.66);
  backdrop-filter: blur(3px);
  animation: overlayIn 0.2s ease-out;
}

[data-motion="reduced"] .overlay { animation: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-card {
  width: min(100%, 420px);
  padding: 26px 24px;
  text-align: center;
  animation: cardIn 0.25s ease-out;
}

[data-motion="reduced"] .overlay-card { animation: none; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.overlay-card h2 { margin: 0 0 6px; font-size: 1.5rem; }

.overlay-sub { margin: 0 0 18px; color: var(--color-muted); }

.emblem {
  width: 74px;
  height: 74px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, rgba(212, 175, 55, 0.25), transparent 70%),
              var(--color-surface-2);
  border: 2px solid var(--color-gold);
  color: var(--color-gold);
}

.emblem svg { width: 58%; height: 58%; }

[data-motion="full"] .overlay-card .emblem { animation: emblemSpin 0.7s ease-out; }

@keyframes emblemSpin {
  from { transform: rotate(-12deg) scale(0.6); opacity: 0; }
  to   { transform: rotate(0) scale(1); opacity: 1; }
}

.achievement-note {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--color-gold);
  background: rgba(212, 175, 55, 0.1);
  color: var(--color-gold);
  font-weight: 600;
  font-size: 0.92rem;
}

.tip {
  margin: 0 0 16px;
  font-size: 0.85rem;
  color: var(--color-muted);
  font-style: italic;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--color-gold);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, translate 0.25s ease;
  translate: 0 8px;
}

.toast.show {
  opacity: 1;
  translate: 0 0;
}

[data-motion="reduced"] .toast { transition: none; }

/* ---------- Reduced motion master switch ---------- */

[data-motion="reduced"] * ,
[data-motion="reduced"] *::before,
[data-motion="reduced"] *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
}
