:root {
  --paper: #f7f4ec;
  --paper-deep: #e8e2d5;
  --ink: #1a1917;
  --ink-soft: #706b61;
  --accent: #b53b2c;
  --absent: #aaa397;
  --line: rgba(26, 25, 23, 0.18);
  --serif: "Noto Serif KR Variable", "Noto Serif KR", serif;
  --sans: "Noto Sans KR Variable", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  background: radial-gradient(circle at 50% 20%, rgba(255,255,255,.92), transparent 38rem), var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  word-break: keep-all;
}
button, input { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.skip-link { position: fixed; z-index: 100; top: .75rem; left: .75rem; padding: .65rem .9rem; background: var(--ink); color: white; transform: translateY(-180%); }
.skip-link:focus { transform: none; }
[hidden] { display: none !important; }
.relay-nav-link { display: inline-grid; place-items: center; width: auto; min-width: 4.9rem; text-decoration: none; }

.welcome {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100svh;
  padding: max(2rem, env(safe-area-inset-top)) 1.5rem max(2rem, env(safe-area-inset-bottom));
  overflow: hidden;
  text-align: center;
}
.glyph-field { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.glyph-field span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  color: rgba(26, 25, 23, .055);
  font-family: var(--serif);
  font-size: clamp(4.5rem, 12vw, 10rem);
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: glyph-drift var(--d) ease-in-out var(--delay) infinite alternate;
}
@keyframes glyph-drift {
  0% { transform: translate(-50%, -50%) rotate(var(--r)) scale(.94); }
  45% { transform: translate(calc(-50% + 16px), calc(-50% - 20px)) rotate(calc(var(--r) + 5deg)) scale(1.03); }
  100% { transform: translate(calc(-50% - 12px), calc(-50% + 18px)) rotate(calc(var(--r) - 4deg)) scale(.98); }
}
.welcome-mark {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(76vw, 330px);
  margin-bottom: clamp(2rem, 6vh, 4rem);
  border: 2px solid var(--ink);
  background: var(--paper);
  box-shadow: 10px 10px 0 var(--ink);
}
.welcome-mark span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-right: 1px solid var(--ink);
  font-family: var(--serif);
  font-size: clamp(2.2rem, 10vw, 4.4rem);
  font-weight: 900;
  line-height: 1;
}
.welcome-mark span:last-child { border-right: 0; }
.eyebrow, .dialog-kicker { margin: 0 0 .55rem; color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .18em; }
.game-portal { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; width: min(92vw, 720px); }
.portal-card { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; min-width: 0; min-height: 10.5rem; padding: 1.35rem; border: 1.5px solid var(--ink); border-radius: 0; background: rgba(251,249,243,.9); color: var(--ink); text-align: left; text-decoration: none; cursor: pointer; box-shadow: 6px 7px 0 rgba(26,25,23,.16); transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease; }
.portal-card:hover { transform: translate(-3px, -3px); box-shadow: 9px 10px 0 var(--ink); }
.portal-card:active { transform: none; box-shadow: 3px 4px 0 var(--ink); }
.portal-card:disabled { opacity: .58; cursor: wait; }
.portal-card:disabled:hover { transform: none; box-shadow: 6px 7px 0 rgba(26,25,23,.16); }
.portal-card-visual { display: grid; grid-template-columns: repeat(3, 1fr); width: 4.3rem; border: 1px solid var(--ink); }
.portal-card-visual i { display: grid; aspect-ratio: 1; place-items: center; border-right: 1px solid var(--ink); font-family: var(--serif); font-size: .8rem; font-style: normal; font-weight: 900; }
.portal-card-visual i:last-child { border-right: 0; }
.portal-lines { display: grid; grid-template-columns: 1fr; gap: .42rem; padding: .8rem .65rem; border-color: var(--accent); }
.portal-lines i { display: block; width: 100%; height: 1px; border: 0; background: var(--accent); }
.portal-lines i:nth-child(2) { width: 76%; }
.portal-lines i:nth-child(3) { width: 88%; }
.portal-card-copy { display: grid; gap: .15rem; min-width: 0; }
.portal-card-copy small { color: var(--accent); font-size: .7rem; font-weight: 850; letter-spacing: .09em; }
.portal-card-copy strong { font-family: var(--serif); font-size: clamp(1.15rem, 3vw, 1.45rem); }
.portal-card-copy > span { color: var(--ink-soft); font-size: .76rem; }
.portal-arrow { align-self: end; font-size: 1.15rem; font-weight: 800; transition: transform 180ms ease; }
.portal-card:hover .portal-arrow { transform: translateX(3px); }

.primary-button {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 3rem;
  min-width: min(88vw, 300px);
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  font-weight: 750;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.primary-button:hover { transform: translate(-3px, -3px); box-shadow: 6px 6px 0 var(--accent); }
.primary-button:active { transform: none; box-shadow: none; }
.primary-button:disabled { opacity: .52; cursor: wait; }
.primary-button:disabled:hover { transform: none; box-shadow: none; }
.primary-button.small { min-width: 0; margin: 0; gap: 1rem; }
.welcome.is-leaving { animation: welcome-out 480ms cubic-bezier(.7,0,.3,1) forwards; }
.game.is-entering { animation: game-in 600ms cubic-bezier(.2,.8,.2,1) both; }
@keyframes welcome-out { to { opacity: 0; transform: scale(.985); } }
@keyframes game-in { from { opacity: 0; transform: translateY(16px); } }

.game { min-height: 100svh; padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100% - 2rem, 760px);
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 0 .85rem;
  border-bottom: 1px solid var(--ink);
}
.brand { display: inline-flex; align-items: center; gap: .65rem; padding: 0; border: 0; background: none; font-family: var(--serif); font-size: 1.08rem; font-weight: 900; cursor: pointer; }
.brand-mark { display: grid; place-items: center; width: 2rem; height: 2rem; background: var(--ink); color: var(--paper); font-size: 1rem; }
.header-actions { display: flex; gap: .4rem; }
.icon-button { min-width: 2.9rem; height: 2.35rem; padding: 0 .6rem; border: 1px solid var(--line); background: transparent; font-size: .78rem; font-weight: 800; cursor: pointer; }
.icon-button:hover { border-color: var(--ink); }
.game-shell { width: min(100% - 2rem, 520px); margin: 0 auto; padding-top: clamp(.75rem, 2vh, 1.35rem); text-align: center; }
.settings { display: flex; justify-content: center; gap: 1rem; margin-bottom: .65rem; }
.setting-group { display: flex; align-items: center; gap: .4rem; }
.setting-group > span { color: var(--ink-soft); font-size: .7rem; font-weight: 800; }
.segment { display: inline-flex; border: 1px solid var(--line); }
.setting-button { padding: .36rem .58rem; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: .75rem; font-weight: 800; cursor: pointer; }
.setting-button:last-child { border-right: 0; }
.setting-button.is-active { background: var(--ink); color: var(--paper); }
.mode-switch { display: inline-flex; padding: .2rem; background: var(--paper-deep); }
.mode-button { min-width: 4.2rem; padding: .48rem .85rem; border: 0; background: transparent; color: var(--ink-soft); font-size: .85rem; font-weight: 750; cursor: pointer; }
.mode-button.is-active { background: var(--ink); color: white; }
.game-heading { margin: .9rem 0 1rem; }
.game-heading p { margin: 0; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .14em; }
.game-heading h2 { margin: .25rem 0 0; font-family: var(--serif); font-size: clamp(1.45rem, 5vw, 1.85rem); letter-spacing: -.04em; }

.board { --slots: 6; display: grid; gap: .38rem; width: 100%; margin: 0 auto; }
.board[data-slots="6"] { max-width: 430px; }
.board[data-slots="9"] { max-width: 520px; }
.board-row { display: grid; grid-template-columns: repeat(var(--slots), 1fr); gap: .35rem; }
.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  background: rgba(255,255,255,.42);
  font-family: var(--serif);
  font-size: clamp(1.25rem, 5.8vw, 2.05rem);
  font-weight: 900;
  line-height: 1;
  transition: border-color 150ms ease, transform 150ms ease;
}
.tile.has-letter { border-color: var(--ink); transform: scale(1.025); }
.tile.is-correct, .tile.is-present, .tile.is-absent { color: white; border-color: transparent; }
.tile.is-correct { background: var(--ink); }
.tile.is-present { background: var(--accent); }
.tile.is-absent { background: var(--absent); }
.tile.is-revealing { animation: reveal 520ms cubic-bezier(.2,.7,.2,1) both; animation-delay: calc(var(--index) * 110ms); }
.board[data-slots="9"] .tile { font-size: clamp(1.05rem, 4.3vw, 1.65rem); }
@keyframes reveal { 0% { transform: rotateX(0); } 48% { transform: rotateX(88deg); } 100% { transform: rotateX(0); } }
.board-row.is-shaking { animation: shake 360ms ease; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

.message { min-height: 1.55rem; margin: .65rem 0 .2rem; color: var(--accent); font-size: .86rem; font-weight: 700; }
.guess-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.input-row input { width: 100%; min-width: 0; padding: .82rem 1rem; border: 1.5px solid var(--ink); border-radius: 0; background: rgba(255,255,255,.55); color: var(--ink); font-family: var(--serif); font-size: 1.05rem; font-weight: 800; letter-spacing: .2em; }
.submit-button { padding: .75rem 1.15rem; border: 1.5px solid var(--ink); background: var(--ink); color: white; font-weight: 800; cursor: pointer; }
.submit-button:disabled, .input-row input:disabled { opacity: .5; cursor: not-allowed; }
.quiet-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem 1.4rem; margin-top: .8rem; }
.quiet-actions button, .text-button { padding: .25rem 0; border: 0; border-bottom: 1px solid currentColor; background: none; color: var(--ink-soft); font-size: .84rem; cursor: pointer; }
.quiet-actions button:disabled { opacity: .4; cursor: default; }
.hint { margin: .8rem 0 0; padding: .8rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-family: var(--serif); font-size: .92rem; }

.dialog { width: min(calc(100% - 2rem), 430px); padding: clamp(1.5rem, 6vw, 2.25rem); border: 1px solid var(--ink); border-radius: 0; background: var(--paper); color: var(--ink); box-shadow: 12px 12px 0 var(--ink); }
.dialog::backdrop { background: rgba(26,25,23,.55); backdrop-filter: blur(3px); }
.dialog[open] { animation: dialog-in 220ms ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dialog-close { position: absolute; top: .75rem; right: .85rem; border: 0; background: none; font-size: 1.6rem; cursor: pointer; }
.dialog h2 { margin: 0 0 1rem; font-family: var(--serif); font-size: 1.75rem; letter-spacing: -.04em; }
.help-copy { margin: -.35rem 0 1rem; color: var(--ink-soft); font-family: var(--serif); }
.example { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; margin: 1.4rem 0; }
.example .tile { font-size: 1.5rem; }
.rules { margin: 0; padding-left: 1.2rem; color: var(--ink-soft); }
.rules li + li { margin-top: .55rem; }
.rules strong { color: var(--ink); }
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: .45rem; margin: 1.4rem 0; }
.stat { padding: .75rem .2rem; border-top: 1px solid var(--ink); text-align: center; }
.stat strong { display: block; font-family: var(--serif); font-size: 1.65rem; }
.stat span { color: var(--ink-soft); font-size: .72rem; }
.distribution { display: grid; gap: .4rem; }
.bar-row { display: grid; grid-template-columns: 1rem 1fr; align-items: center; gap: .55rem; font-size: .78rem; }
.bar { min-width: 1.6rem; padding: .2rem .4rem; background: var(--ink); color: white; text-align: right; transition: width 400ms ease; }
.result-dialog h2 { font-size: 2.6rem; }
.definition { color: var(--ink-soft); font-family: var(--serif); }
.source-copy { color: var(--ink-soft); }
.source-copy a, .source-list a, .data-link { color: var(--ink); text-underline-offset: .2em; }
.source-list { margin: 1.25rem 0; }
.source-list > div { display: grid; grid-template-columns: 5.2rem 1fr; gap: .75rem; padding: .65rem 0; border-top: 1px solid var(--line); }
.source-list > div:last-child { border-bottom: 1px solid var(--line); }
.source-list dt { font-size: .78rem; font-weight: 800; }
.source-list dd { margin: 0; color: var(--ink-soft); font-size: .84rem; }
.source-note { color: var(--ink-soft); font-size: .78rem; }
.data-link { display: inline-block; margin-top: .25rem; font-size: .82rem; font-weight: 800; }
.result-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); padding: .7rem 1rem; background: var(--ink); color: white; font-size: .85rem; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 740px) {
  .game-shell { padding-top: .8rem; }
  .settings { margin-bottom: .45rem; }
  .game-heading { margin: .7rem 0 .8rem; }
  .board { width: min(100%, 380px); gap: .3rem; }
  .board-row { gap: .3rem; }
  .tile { font-size: 1.65rem; }
  .message { margin-top: .35rem; }
}
@media (max-width: 420px) {
  .board-row { gap: .25rem; }
  .settings { gap: .45rem; }
  .setting-group { gap: .25rem; }
  .setting-group > span { display: none; }
  .setting-button { padding-inline: .52rem; }
  .board[data-slots="9"] .board-row { gap: .18rem; }
}
@media (max-width: 420px) {
  .welcome-mark { box-shadow: 7px 7px 0 var(--ink); }
  .welcome-mark { width: min(62vw, 250px); margin-bottom: 2rem; }
  .game-portal { grid-template-columns: 1fr; width: min(100%, 390px); gap: .75rem; }
  .portal-card { min-height: 7.4rem; padding: 1rem; }
  .game-header, .game-shell { width: min(100% - 1.25rem, 430px); }
  .dialog { box-shadow: 7px 7px 0 var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
