@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;600;700&family=Song+Myung&display=swap");

:root {
  color-scheme: light;
  --ink: #18282d;
  --deep: #17343b;
  --deep-soft: #21454c;
  --celadon: #b8d2cb;
  --celadon-light: #dbe7e1;
  --paper: #f5f2e9;
  --paper-muted: #e7e4da;
  --wood-light: #e6bb78;
  --wood-dark: #82512c;
  --cinnabar: #c94b3f;
  --cinnabar-dark: #96362f;
  --shadow: rgba(6, 24, 28, .26);
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 4%, rgba(255,255,255,.07), transparent 30%),
    linear-gradient(145deg, #1d4149 0%, var(--deep) 54%, #102a30 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

button:focus-visible {
  outline: 4px solid #f2ca64;
  outline-offset: 4px;
}

.game-shell {
  width: min(100%, 1200px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(30px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(30px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.38);
  border-radius: 50%;
  color: #fff9ed;
  background: var(--cinnabar);
  box-shadow: 0 7px 20px rgba(95, 27, 24, .26);
  font-family: "Song Myung", serif;
  font-size: 29px;
  line-height: 1;
}

h1,
.brand p,
.result-panel p,
.history h2 { margin: 0; }

h1 {
  font-family: "Song Myung", serif;
  font-size: clamp(31px, 3.7vw, 42px);
  font-weight: 400;
  line-height: .95;
  letter-spacing: -.05em;
}

.brand p {
  margin-top: 8px;
  color: rgba(226, 241, 237, .7);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .13em;
}

.sound-button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid rgba(222, 239, 234, .24);
  border-radius: 999px;
  color: rgba(255,255,255,.84);
  background: rgba(255,255,255,.055);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.sound-button:hover {
  border-color: rgba(222, 239, 234, .42);
  background: rgba(255,255,255,.09);
}

.sound-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-off,
.sound-button[aria-pressed="false"] .sound-on { display: none; }
.sound-button[aria-pressed="false"] .sound-off { display: block; }

[data-player-slot="0"] { --player-color: #c94b3f; --player-color-dark: #96362f; }
[data-player-slot="1"] { --player-color: #2f6f76; --player-color-dark: #204e54; }
[data-player-slot="2"] { --player-color: #a46616; --player-color-dark: #74470d; }
[data-player-slot="3"] { --player-color: #765a8a; --player-color-dark: #533d64; }
[data-player-slot="4"] { --player-color: #607149; --player-color-dark: #425033; }
[data-player-slot="5"] { --player-color: #426a91; --player-color-dark: #2d4a67; }

.turn-strip {
  display: grid;
  grid-template-columns: minmax(180px, .72fr) minmax(470px, 1.8fr);
  align-items: center;
  gap: 18px;
  margin-top: 20px;
  padding: 12px 14px 12px 22px;
  border: 1px solid rgba(255,255,255,.66);
  border-radius: 19px;
  background: rgba(245, 242, 233, .97);
  box-shadow: 0 14px 34px rgba(5, 22, 25, .16);
}

.turn-callout {
  position: relative;
  min-width: 0;
  padding-left: 16px;
}

.turn-callout::before {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 4px;
  border-radius: 4px;
  background: var(--player-color, var(--cinnabar));
  content: "";
}

.turn-eyebrow,
.turn-callout h2,
.player-setup-label { margin: 0; }

.turn-eyebrow,
.player-setup-label {
  color: #697a78;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .13em;
}

.turn-callout h2 {
  margin-top: 2px;
  color: var(--deep);
  font-size: 18px;
  line-height: 1.2;
}

#currentPlayerName {
  color: var(--player-color, var(--cinnabar));
  font-family: "Song Myung", serif;
  font-size: 30px;
  font-weight: 400;
  letter-spacing: -.04em;
}

.player-setup { min-width: 0; }

.player-setup-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 24px;
  margin: 0 2px 7px;
}

.player-setup-label { margin: 0; }

.player-setup-guide {
  margin: 2px 0 0;
  color: #899591;
  font-size: 9px;
  font-weight: 600;
}

.new-game-button {
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid #b8c1bc;
  border-radius: 999px;
  color: #596a68;
  background: rgba(255,255,255,.45);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.new-game-button:hover {
  border-color: var(--cinnabar);
  color: var(--cinnabar-dark);
}

.new-game-button:disabled {
  opacity: .45;
  cursor: wait;
}

.new-game-button[hidden],
.capture-button[hidden] { display: none; }

.player-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
}

.player-count-control {
  display: grid;
  grid-template-columns: auto 28px 37px 28px;
  align-items: center;
  gap: 3px;
  min-height: 44px;
  padding: 5px 6px 5px 9px;
  border: 1px solid #ccd3cb;
  border-radius: 11px;
  background: rgba(255,255,255,.48);
}

.player-count-label {
  margin-right: 3px;
  color: #697a78;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
}

.player-count-control button {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border: 1px solid #b8c3bd;
  border-radius: 50%;
  color: var(--deep-soft);
  background: #fffdf7;
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
}

.player-count-control button:hover:not(:disabled) {
  border-color: var(--cinnabar);
  color: var(--cinnabar-dark);
}

.player-count-control button:disabled {
  opacity: .34;
  cursor: default;
}

.player-count-control output {
  color: var(--deep);
  font-family: "Song Myung", serif;
  font-size: 17px;
  text-align: center;
  white-space: nowrap;
}

.player-name-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 7px;
}

.player-name-card {
  display: flex;
  min-width: 0;
  min-height: 44px;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid #ccd3cb;
  border-radius: 11px;
  background: rgba(255,255,255,.48);
  box-shadow: inset 0 3px 0 var(--player-color);
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.player-name-card:focus-within {
  border-color: var(--player-color);
  outline: 3px solid rgba(242, 202, 100, .62);
  outline-offset: 2px;
}

.player-number {
  display: grid;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--player-color);
  font-family: "Song Myung", serif;
  font-size: 12px;
  line-height: 1;
}

.player-name-card input {
  width: 100%;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  outline: 0;
  color: var(--deep);
  background: transparent;
  font: 700 14px/1.3 "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  user-select: text;
}

.player-name-card input:disabled {
  opacity: 1;
  -webkit-text-fill-color: currentColor;
}

.player-name-card.is-current {
  border-color: var(--player-color-dark);
  color: white;
  background: var(--player-color);
  box-shadow: 0 4px 0 var(--player-color-dark);
  transform: translateY(-2px);
}

.player-name-card.is-current .player-number {
  color: var(--player-color);
  background: white;
}

.player-name-card.is-current input { color: white; }

.player-setup-status {
  min-height: 13px;
  margin: 5px 2px 0;
  color: #7b8986;
  font-size: 9px;
  font-weight: 600;
}

.capture-button {
  display: flex;
  align-self: center;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 112px;
  min-height: 38px;
  margin: 0 auto 13px;
  padding: 5px 8px;
  border: 1px solid #a5b3ad;
  border-radius: 9px;
  color: var(--deep-soft);
  background: transparent;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
}

.capture-button strong {
  display: block;
  color: var(--cinnabar-dark);
  font-size: 11px;
}

.capture-button:not(:disabled):hover {
  border-color: var(--cinnabar);
  background: rgba(201,75,63,.06);
}

.capture-button:not([hidden]) {
  animation: capture-reveal 180ms ease-out;
}

.capture-button:disabled {
  opacity: .34;
  cursor: default;
}

.capture-icon {
  color: var(--cinnabar);
  font-family: sans-serif;
  font-size: 17px;
  line-height: 1;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(236px, .68fr) minmax(460px, 1.62fr);
  grid-template-rows: auto 1fr;
  gap: 20px 24px;
  margin-top: 16px;
}

.result-panel {
  position: relative;
  align-self: stretch;
  min-height: 214px;
  padding: 30px 30px 28px 34px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.62);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 18px 44px rgba(5, 22, 25, .18);
}

.result-panel::before {
  position: absolute;
  top: 28px;
  bottom: 28px;
  left: 0;
  width: 5px;
  border-radius: 0 5px 5px 0;
  background: var(--cinnabar);
  content: "";
}

.result-kicker {
  color: #667878;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .16em;
}

.result-name {
  margin: 9px 0 4px;
  color: var(--cinnabar);
  font-family: "Song Myung", serif;
  font-size: clamp(68px, 8.3vw, 104px);
  font-weight: 400;
  line-height: .94;
  letter-spacing: -.08em;
}

.result-detail {
  max-width: 270px;
  color: #586766;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.55;
}

.mat-wrap {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: min(62svh, 665px);
}

.mat {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 480px;
  place-items: center;
  overflow: hidden;
  border: 8px solid var(--celadon-light);
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% 46%, rgba(255,255,255,.25) 0 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(145deg, #c4d9d2, #adcac3);
  box-shadow:
    inset 0 0 0 1px rgba(25,65,67,.12),
    inset 0 20px 50px rgba(255,255,255,.16),
    0 24px 58px rgba(3, 20, 24, .3);
  perspective: 900px;
}

.yut-canvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  overflow: hidden;
  border-radius: 22px;
  touch-action: manipulation;
}

.yut-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 19px;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 22px;
  background: rgba(245, 242, 233, .97);
  box-shadow: 0 18px 44px rgba(5, 22, 25, .18);
}

.throw-button {
  position: relative;
  width: 100%;
  min-height: 110px;
  padding: 18px 22px 17px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  color: white;
  background: linear-gradient(180deg, #d25549, var(--cinnabar));
  box-shadow: 0 7px 0 var(--cinnabar-dark), 0 16px 24px rgba(123,39,34,.2);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 160ms ease;
}

.throw-button::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 25%, rgba(255,255,255,.1) 45%, transparent 65%);
  content: "";
  pointer-events: none;
}

.throw-button:hover { filter: brightness(1.04); }

.throw-button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--cinnabar-dark), 0 8px 14px rgba(123,39,34,.17);
}

.throw-button:disabled {
  cursor: wait;
  filter: saturate(.6);
}

.throw-main,
.throw-hint { display: block; }

.throw-main {
  position: relative;
  z-index: 1;
  font-family: "Song Myung", serif;
  font-size: clamp(31px, 3.8vw, 40px);
  line-height: 1.1;
  letter-spacing: -.04em;
}

.throw-hint {
  position: relative;
  z-index: 1;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  opacity: .78;
}

.history {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 68px;
  margin-top: 20px;
  padding: 13px 18px;
  border-top: 1px solid rgba(222,239,234,.17);
  color: white;
}

.history h2 {
  flex: 0 0 auto;
  color: rgba(226,241,237,.58);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
}

.history ol {
  display: flex;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li:not(.empty-history) {
  display: grid;
  min-width: 68px;
  height: 49px;
  padding: 5px 10px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  color: var(--ink);
  background: var(--paper-muted);
  box-shadow: inset 0 3px 0 var(--player-color, var(--deep-soft));
  font-family: "Song Myung", serif;
  font-size: 19px;
  line-height: 1;
}

.history li:first-child:not(.empty-history) {
  color: var(--ink);
  background: #fffaf0;
  box-shadow:
    inset 0 0 0 2px var(--player-color, var(--deep-soft)),
    0 4px 10px rgba(5, 22, 25, .12);
}

.history-player {
  min-width: 38px;
  padding: 2px 5px;
  border-radius: 999px;
  color: white;
  background: var(--player-color, var(--deep-soft));
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.empty-history {
  color: rgba(226,241,237,.42);
  font-size: 12px;
}

@media (max-width: 760px), (orientation: portrait) and (max-width: 1100px) {
  .game-shell { padding-inline: 20px; }
  .turn-strip {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 13px 14px 14px 18px;
  }
  .turn-callout { grid-column: 1; grid-row: 1; }
  .player-setup { grid-column: 1; grid-row: 2; }
  .player-name-fields { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); }
  .play-area { grid-template-columns: 1fr; }
  .result-panel { min-height: 0; padding: 21px 26px 22px 30px; }
  .result-panel::before { top: 20px; bottom: 20px; }
  .result-name { display: inline-block; margin-right: 13px; font-size: 60px; }
  .result-detail { display: inline; font-size: 14px; }
  .controls { grid-row: 2; padding-block: 15px; }
  .mat-wrap { grid-column: 1; grid-row: 3; min-height: 48svh; }
  .mat { min-height: 390px; }
}

@media (max-width: 540px) {
  .brand p,
  .sound-button span,
  .history h2 { display: none; }
  .sound-button { width: 48px; padding: 0; justify-content: center; }
  .turn-strip { margin-top: 14px; }
  .player-editor { grid-template-columns: 1fr; }
  .player-count-control { justify-self: start; }
  .player-name-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-name { display: block; margin-right: 0; }
  .result-detail { display: block; }
  .capture-button { width: 104px; }
  .mat { min-height: 350px; border-width: 6px; }
  .history { overflow: hidden; padding-inline: 4px; }
  .history ol { gap: 5px; }
  .history li:not(.empty-history) { min-width: 58px; padding-inline: 6px; }
}

@keyframes capture-reveal {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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