@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=Playfair+Display:ital,wght@0,600;1,600&display=swap');

:root {
  --paper: #f6f0e5;
  --paper-deep: #eee3d2;
  --ink: #26322f;
  --muted: #7a7d71;
  --coral: #e36751;
  --coral-soft: #f3c5b8;
  --teal: #278b82;
  --teal-soft: #b8d9d2;
  --line: rgba(38, 50, 47, .16);
  --shadow: 0 24px 70px rgba(82, 63, 38, .12), 0 3px 10px rgba(82, 63, 38, .07);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(255,255,255,.75), transparent 30rem),
    radial-gradient(circle at 92% 90%, rgba(227,103,81,.07), transparent 26rem),
    var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .23;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

button { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.shell {
  width: min(760px, calc(100% - 48px));
  min-height: calc(100vh - 50px);
  margin: 0 auto;
  padding: 28px 0 14px;
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(31px, 4vw, 42px);
  line-height: .95;
  letter-spacing: -.035em;
}

h1 span { color: var(--coral); }

.utility-controls { display: flex; align-items: center; gap: 5px; }
.quiet-toggle {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: 8px 10px; color: var(--muted); background: transparent; cursor: pointer;
  font-size: 11px; font-weight: 600; transition: .2s ease;
}
.quiet-toggle:hover { color: var(--ink); background: rgba(255,255,255,.45); }
.quiet-toggle[aria-pressed="true"] { color: var(--teal); }
.quiet-toggle[hidden] { display: none; }

.mode-switch {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.35);
}

.mode-button {
  border: 0;
  border-radius: 999px;
  padding: 9px 15px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: .2s ease;
}

.mode-button:hover { color: var(--ink); }
.mode-button.active {
  color: var(--ink);
  background: #fffaf1;
  box-shadow: 0 2px 9px rgba(62,49,30,.1);
}

.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px 0 10px;
}

.top-controls { width: min(100%, 380px); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.difficulty-switch { display: flex; gap: 2px; }
.difficulty-button {
  border: 0; border-bottom: 1px solid transparent; padding: 7px 6px; color: #969286;
  background: transparent; cursor: pointer; font-size: 10px; font-weight: 600; transition: .2s ease;
}
.difficulty-button:hover { color: var(--ink); }
.difficulty-button.active { color: var(--teal); border-color: var(--teal); }
.difficulty-switch[hidden] { display: none; }

.score-card { width: min(100%, 380px); display: grid; grid-template-columns: 1fr 1px 1fr 1px 1fr; }
.sound-settings { width: min(100%, 380px); margin-top: -5px; color: #969286; font-size: 10px; text-align: center; }
.sound-settings summary { display: inline-block; cursor: pointer; list-style: none; padding: 3px 8px; }
.sound-settings summary::-webkit-details-marker { display: none; }
.sound-row { display: grid; grid-template-columns: 28px minmax(100px, 1fr) 28px minmax(70px, .55fr); gap: 5px; align-items: center; margin-top: 5px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.3); }
.sound-row button { border: 0; padding: 5px; color: var(--muted); background: transparent; cursor: pointer; }
.sound-row select { width: 100%; border: 0; padding: 5px; color: var(--ink); background: transparent; font: 600 10px "DM Sans", sans-serif; }
.volume-control { display: flex; align-items: center; gap: 4px; }
.volume-control input { width: 100%; height: 3px; accent-color: var(--teal); cursor: pointer; }

.score-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 7px 10px;
  color: var(--muted);
  transition: color .2s ease;
}

.score-row.is-active { color: var(--ink); }
.score-row:first-child { padding-left: 0; }
.score-row:last-child { padding-right: 0; }
.score-row strong { color: var(--ink); font-family: "Playfair Display", serif; font-size: 18px; }
.score-name { font-size: 11px; font-weight: 600; }
.score-divider { width: 1px; height: auto; background: var(--line); }
.mini-mark { width: 17px; height: 17px; position: relative; display: inline-block; }
.mini-x::before, .mini-x::after {
  content: ""; position: absolute; left: 7px; top: -1px; width: 3px; height: 19px;
  border-radius: 2px; background: var(--coral); transform: rotate(45deg);
}
.mini-x::after { transform: rotate(-45deg); }
.mini-o { border: 3px solid var(--teal); border-radius: 50%; }
.dash { color: #aa9f8e; font-family: Georgia, serif; font-size: 20px; }

.play-area { width: min(100%, 380px); }
.status-wrap { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 16px; }
.status, .round-label { margin: 0; font-size: 12px; }
.status { font-weight: 600; letter-spacing: .02em; }
.round-label { color: var(--muted); }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; vertical-align: 1px; }
.x-dot { background: var(--coral); box-shadow: 0 0 0 4px rgba(227,103,81,.12); }
.o-dot { background: var(--teal); box-shadow: 0 0 0 4px rgba(39,139,130,.12); }
.neutral-dot { background: #a0988b; box-shadow: 0 0 0 4px rgba(90,85,75,.1); }

.board-wrap { position: relative; }
.board {
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid rgba(38,50,47,.2);
  border-radius: 25px;
  overflow: hidden;
  background: rgba(255, 252, 246, .82);
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  transition: background .18s ease;
}
.cell:nth-child(3n) { border-right: 0; }
.cell:nth-child(n+7) { border-bottom: 0; }
.cell:not(:disabled):hover { background: rgba(255,255,255,.62); }
.cell:focus-visible { outline: 3px solid rgba(227,103,81,.48); outline-offset: -5px; z-index: 3; }
.cell:disabled { cursor: default; }
.cell.winning { background: rgba(255,255,255,.55); }

.mark { width: 54%; height: 54%; position: relative; animation: mark-in .28s cubic-bezier(.2,.9,.25,1.2) both; }
.mark.x::before, .mark.x::after {
  content: ""; position: absolute; left: 46%; top: 3%; width: 8%; height: 94%; border-radius: 99px;
  background: var(--coral); transform: rotate(45deg);
  box-shadow: 0 2px 0 rgba(132,58,43,.12);
}
.mark.x::after { transform: rotate(-45deg); }
.mark.o { border: clamp(7px, 1vw, 10px) solid var(--teal); border-radius: 50%; box-shadow: inset 0 2px 0 rgba(255,255,255,.6), 0 2px 0 rgba(28,91,86,.1); }

.win-line { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.win-line line {
  stroke: var(--ink); stroke-width: 6; stroke-linecap: round; opacity: 0;
  stroke-dasharray: 300; stroke-dashoffset: 300;
}
.win-line.show line { opacity: .72; animation: line-in .45s .13s ease-out forwards; }

.actions { display: flex; justify-content: center; align-items: center; gap: 20px; margin-top: 15px; }
.primary-action, .text-action { cursor: pointer; }
.primary-action {
  border: 0; border-radius: 999px; padding: 12px 19px; color: #fffaf2; background: var(--ink);
  font-size: 12px; font-weight: 600; box-shadow: 0 5px 14px rgba(38,50,47,.18); transition: .2s ease;
}
.primary-action:hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(38,50,47,.22); }
.primary-action span { margin-left: 7px; }
.text-action { border: 0; padding: 8px 2px; color: var(--muted); background: transparent; font-size: 12px; border-bottom: 1px solid transparent; }
.text-action:hover { color: var(--ink); border-color: var(--line); }

.note-card {
  position: relative;
  max-width: 190px;
  padding: 20px 0 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.note-number { color: var(--coral); font-family: "Playfair Display", serif; font-size: 12px; font-style: italic; }
.note-card p { margin: 12px 0 8px; color: var(--muted); font-family: "Playfair Display", Georgia, serif; font-size: 16px; font-style: italic; line-height: 1.55; }
.scribble { display: block; width: 35px; height: 15px; margin-left: auto; border-bottom: 2px solid var(--teal); border-radius: 50%; transform: rotate(-8deg); opacity: .6; }

footer {
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  padding: 0 0 12px;
  color: #9b9488;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 11px;
  font-style: italic;
  text-align: center;
}
.daily-quote { min-height: 18px; margin: 0 0 6px; color: #817d73; font-size: 13px; }
.daily-quote::before, .daily-quote::after { color: var(--coral); opacity: .6; }
.daily-quote::before { content: "“"; }
.daily-quote::after { content: "”"; }
.credits { display: inline-block; color: #a09a8e; font-family: "DM Sans", sans-serif; font-style: normal; font-size: 9px; }
.credits summary { cursor: pointer; list-style: none; }
.credits summary::-webkit-details-marker { display: none; }
.credits p { max-width: 380px; margin: 6px auto 0; line-height: 1.5; }
.credits a { color: inherit; text-underline-offset: 2px; }

@keyframes mark-in { from { opacity: 0; transform: scale(.55) rotate(-8deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes line-in { to { stroke-dashoffset: 0; } }

@media (max-width: 820px) {
  .shell { min-height: auto; padding-top: 28px; }
  .game-layout { gap: 14px; padding-top: 20px; }
  .score-row { grid-template-columns: 18px 1fr auto; gap: 7px; }
  .mini-mark { transform: scale(.75); }
}

@media (max-width: 540px) {
  .shell { width: min(100% - 28px, 460px); padding-top: 22px; }
  .masthead { align-items: flex-start; gap: 12px; padding-bottom: 16px; }
  h1 { font-size: 31px; }
  .eyebrow { font-size: 9px; }
  .mode-button { padding: 6px 9px; font-size: 10px; }
  .top-controls { align-items: flex-start; }
  .difficulty-switch { gap: 0; }
  .difficulty-button { padding: 7px 4px; font-size: 9px; }
  .toggle-label { display: none; }
  #sound-label { display: inline; }
  .board { border-radius: 20px; }
  .game-layout { padding-top: 20px; }
  .score-name { font-size: 10px; }
  .score-row strong { font-size: 18px; }
  footer { padding-top: 3px; }
}

@media (max-height: 760px) and (min-width: 821px) {
  .shell { min-height: 0; padding-top: 10px; }
  .masthead { padding-bottom: 7px; }
  h1 { font-size: 29px; }
  .game-layout { padding: 5px 0 3px; gap: 4px; }
  .play-area { max-width: 325px; }
  .top-controls, .score-card, .sound-settings { max-width: 360px; }
  .status-wrap { margin-bottom: 6px; }
  .actions { margin-top: 6px; }
  footer { padding-bottom: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
