:root {
  --ink: #241811;
  --muted: #765846;
  --paper: #f3dfa9;
  --wood: #513325;
  --wood-dark: #1d120d;
  --green: #79e348;
  --red: #b84436;
  --gold: #ffd998;
  --slot: #1c120e;
  --shadow: 0 18px 50px rgba(19, 10, 5, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 54px 54px,
    linear-gradient(135deg, #2a1a14, #6b4431 45%, #2e1b14);
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

.lobby-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}

.lobby-panel {
  width: min(760px, 100%);
  padding: clamp(18px, 4vw, 32px);
  border: 7px solid rgba(54, 41, 32, 0.9);
  border-radius: 10px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.12)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 3px, transparent 3px 17px),
    var(--wood);
  color: var(--gold);
  box-shadow: var(--shadow);
}

.lobby-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.lobby-box {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 3px solid rgba(72, 42, 24, 0.48);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.02)),
    var(--paper);
  color: var(--ink);
}

.lobby-box h2 {
  font-size: 1.15rem;
}

.lobby-box p,
.lobby-message {
  line-height: 1.45;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
}

.room-input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 3px solid rgba(52, 33, 24, 0.34);
  border-radius: 8px;
  background: #fff6d6;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.lobby-message {
  margin-top: 14px;
  color: #ffe5ad;
  font-weight: 900;
}

.game-shell {
  width: min(1220px, calc(100vw - 20px));
  min-height: calc(100vh - 20px);
  margin: 10px auto;
  padding: clamp(12px, 2.2vw, 24px);
  border: 7px solid rgba(54, 41, 32, 0.9);
  border-radius: 10px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.12)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 3px, transparent 3px 17px),
    var(--wood);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  color: var(--gold);
}

.eyebrow {
  margin-bottom: 3px;
  color: #eac17d;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
}

.scoreboard {
  display: flex;
  gap: 10px;
}

.score-card {
  min-width: 92px;
  padding: 10px 14px;
  border: 2px solid rgba(255, 217, 152, 0.32);
  border-radius: 8px;
  background: rgba(24, 13, 9, 0.46);
  text-align: center;
}

.score-card span {
  display: block;
  color: #f3ca84;
  font-size: 0.82rem;
  font-weight: 900;
}

.score-card strong {
  display: block;
  color: #ffe3aa;
  font-size: 2rem;
  line-height: 1;
}

.table {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.control-panel,
.battle-panel {
  border: 3px solid rgba(72, 42, 24, 0.48);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.02)),
    var(--paper);
  box-shadow: inset 0 0 36px rgba(122, 71, 28, 0.2);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.current-roll {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 246, 215, 0.55);
}

.room-badge {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(30, 18, 12, 0.86);
  color: #ffe1a5;
  text-align: center;
}

.room-badge span {
  font-size: 0.78rem;
  font-weight: 900;
}

.room-badge strong {
  font-size: 1.55rem;
  letter-spacing: 0;
}

.current-roll span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.choice-dice {
  display: grid;
  grid-template-columns: repeat(2, 82px);
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.choice-die {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 5px;
  border: 3px solid rgba(52, 33, 24, 0.32);
  border-radius: 8px;
  background: rgba(255, 246, 215, 0.7);
  cursor: pointer;
}

.choice-die .die {
  width: 64px;
}

.choice-die.selected {
  border-color: #ffd16d;
  box-shadow: 0 0 0 3px rgba(255, 209, 109, 0.28);
}

.choice-die:disabled {
  cursor: default;
  opacity: 0.72;
}

.skill-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.skill-action {
  min-height: 42px;
  padding: 0 10px;
  border: 2px solid rgba(52, 33, 24, 0.34);
  border-radius: 8px;
  background: #7a4c2f;
  color: #fff3c8;
  cursor: pointer;
  font-weight: 900;
}

.skill-action.danger {
  background: #8d3f36;
}

.skill-action:disabled {
  cursor: default;
  opacity: 0.55;
}

.status {
  min-height: 72px;
  padding: 12px;
  border-left: 5px solid var(--red);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.35);
  color: #422b20;
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.45;
}

.primary-action {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: #2e663a;
  color: #fff7d8;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 7px 0 #18371f;
}

.secondary-action {
  min-height: 42px;
  border: 2px solid rgba(52, 33, 24, 0.34);
  border-radius: 8px;
  background: rgba(255, 246, 215, 0.6);
  color: #422b20;
  cursor: pointer;
  font-weight: 900;
}

.primary-action:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #18371f;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: default;
  opacity: 0.55;
}

.rules {
  display: grid;
  gap: 9px;
  color: #493126;
  font-size: 0.88rem;
  line-height: 1.45;
}

.rules h2 {
  font-size: 1rem;
}

.rules p {
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(64, 37, 20, 0.14);
}

.battle-panel {
  padding: 16px;
}

.activity-panel {
  margin-top: 14px;
  padding: 12px;
  border: 3px solid rgba(72, 42, 24, 0.32);
  border-radius: 8px;
  background: rgba(255, 246, 215, 0.46);
}

.activity-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.activity-heading h2 {
  font-size: 1rem;
}

.activity-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.action-log {
  display: grid;
  gap: 6px;
  max-height: 168px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.action-log li {
  padding: 8px 10px;
  border-left: 4px solid rgba(52, 33, 24, 0.32);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.34);
  color: #3f2a20;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

.action-log .log-knock {
  border-left-color: #ff4a36;
  background: rgba(255, 74, 54, 0.13);
}

.action-log .log-skill {
  border-left-color: #7a4c2f;
  background: rgba(122, 76, 47, 0.13);
}

.action-log .log-empty {
  color: var(--muted);
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 8, 5, 0.72);
}

.result-card {
  width: min(440px, 100%);
  padding: 22px;
  border: 6px solid rgba(54, 41, 32, 0.95);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.03)),
    var(--paper);
  color: var(--ink);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

.result-card h2 {
  margin-top: 2px;
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 1;
}

.result-summary {
  margin-top: 8px;
  color: #4d3327;
  font-size: 1.08rem;
  font-weight: 900;
}

.result-lanes {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.result-lane {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  font-weight: 900;
}

.result-lane span {
  color: var(--muted);
}

.result-lane.mine strong {
  color: #2d6638;
}

.result-lane.enemy strong {
  color: #b73e31;
}

.result-lane.tie strong {
  color: #5d5144;
}

.result-card .primary-action,
.result-card .secondary-action {
  width: 100%;
  margin-top: 8px;
}

.field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
}

.field-heading h2 {
  font-size: 1.05rem;
}

.enemy-heading {
  grid-area: enemy-heading;
}

.player-heading {
  grid-area: player-heading;
}

.turn-badge {
  min-width: 66px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(64, 45, 33, 0.17);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
}

.turn-badge.active {
  background: #342118;
  color: #ffdf98;
}

.match-board {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) 96px minmax(230px, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "enemy-heading . player-heading"
    "enemy-board center-rail player-board";
  gap: 10px 8px;
  align-items: stretch;
  min-height: 470px;
}

.enemy-board {
  grid-area: enemy-board;
}

.center-rail {
  grid-area: center-rail;
}

.player-board {
  grid-area: player-board;
}

.board {
  display: grid;
  grid-template-rows: repeat(3, minmax(126px, 1fr));
  gap: 12px;
  padding: 12px;
  border: 4px solid #070403;
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.05), transparent 30%),
    linear-gradient(#201712, #100a08);
}

.column {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(66px, 1fr));
  gap: 10px;
  width: 100%;
  min-height: 0;
  padding: 10px;
  border: 3px solid rgba(244, 223, 170, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035), transparent),
    rgba(255, 245, 213, 0.04);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.lane-pop {
  animation: lane-pop 520ms ease;
}

.lane-recoil {
  animation: lane-recoil 620ms ease;
}

.lane-impact {
  animation: lane-impact 680ms ease;
}

.knock-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border: 2px solid #ffe1a5;
  border-radius: 999px;
  background: #c83427;
  color: #fff3cf;
  font-size: 0.82rem;
  font-weight: 900;
  pointer-events: none;
  animation: burst-pop 700ms ease forwards;
  box-shadow: 0 0 18px rgba(255, 74, 54, 0.62);
}

.enemy-board .column {
  direction: rtl;
}

.enemy-board .slot,
.enemy-board .die {
  direction: ltr;
}

.column.available:hover,
.column.available:focus-visible {
  outline: none;
  transform: translateY(-2px);
  border-color: #ffd16d;
  background: rgba(255, 209, 109, 0.15);
}

.column.disabled {
  cursor: default;
}

.column.knock-ready {
  border-color: #ff4a36;
  background:
    linear-gradient(90deg, rgba(255, 74, 54, 0.24), rgba(255, 74, 54, 0.06)),
    rgba(255, 245, 213, 0.04);
  box-shadow: inset 0 0 18px rgba(255, 74, 54, 0.42), 0 0 14px rgba(255, 74, 54, 0.24);
}

.slot {
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.center-rail {
  display: grid;
  grid-template-columns: 1fr 42px 1fr;
  grid-template-rows: repeat(3, minmax(126px, 1fr));
  gap: 12px 4px;
  align-items: stretch;
}

.column-scores,
.lane-numbers {
  display: contents;
}

.column-score,
.lane-numbers span {
  display: grid;
  place-items: center;
  align-self: center;
  min-height: 42px;
  border: 3px solid #080403;
  border-radius: 999px;
  background: #1b120e;
  font-weight: 900;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.04);
}

.enemy-scores .column-score {
  grid-column: 1;
  color: #baff70;
}

.lane-numbers span {
  grid-column: 2;
  color: #f2b05f;
  font-size: 0.78rem;
}

.player-scores .column-score {
  grid-column: 3;
  color: #ff765f;
}

.enemy-scores .column-score:nth-child(1),
.lane-numbers span:nth-child(1),
.player-scores .column-score:nth-child(1) {
  grid-row: 1;
}

.enemy-scores .column-score:nth-child(2),
.lane-numbers span:nth-child(2),
.player-scores .column-score:nth-child(2) {
  grid-row: 2;
}

.enemy-scores .column-score:nth-child(3),
.lane-numbers span:nth-child(3),
.player-scores .column-score:nth-child(3) {
  grid-row: 3;
}

.die {
  --dot: #245b15;
  position: relative;
  width: min(76px, 100%);
  aspect-ratio: 1;
  border: 3px solid #6f5e4e;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.05) 54%),
    repeating-linear-gradient(90deg, rgba(125, 86, 47, 0.16) 0 2px, transparent 2px 9px),
    #d8c6aa;
  box-shadow: inset 0 0 10px rgba(59, 38, 22, 0.32), 0 8px 13px rgba(0, 0, 0, 0.3);
  color: transparent;
}

.die.big {
  width: 116px;
  max-width: none;
  border-color: #37241d;
}

.die.shield {
  border-color: var(--green);
  box-shadow:
    0 0 0 3px rgba(121, 227, 72, 0.38),
    inset 0 0 10px rgba(59, 38, 22, 0.32),
    0 8px 13px rgba(0, 0, 0, 0.3);
}

.die.threatened {
  border-color: #ff3f32;
  box-shadow:
    0 0 0 3px rgba(255, 63, 50, 0.42),
    0 0 18px rgba(255, 63, 50, 0.55),
    inset 0 0 10px rgba(59, 38, 22, 0.32),
    0 8px 13px rgba(0, 0, 0, 0.3);
}

.pip {
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.32), 0 1px 0 rgba(255, 255, 255, 0.18);
}

.die.big .pip {
  width: 18px;
  height: 18px;
}

.pip.p1 {
  top: 19%;
  left: 19%;
}

.pip.p2 {
  top: 19%;
  left: calc(50% - 7.5px);
}

.pip.p3 {
  top: 19%;
  right: 19%;
}

.pip.p4 {
  top: calc(50% - 7.5px);
  left: 19%;
}

.pip.p5 {
  top: calc(50% - 7.5px);
  left: calc(50% - 7.5px);
}

.pip.p6 {
  top: calc(50% - 7.5px);
  right: 19%;
}

.pip.p7 {
  bottom: 19%;
  left: 19%;
}

.pip.p8 {
  bottom: 19%;
  left: calc(50% - 7.5px);
}

.pip.p9 {
  right: 19%;
  bottom: 19%;
}

@keyframes lane-pop {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.035);
    border-color: #ffd16d;
  }

  100% {
    transform: scale(1);
  }
}

@keyframes lane-recoil {
  0% {
    transform: translateX(0);
  }

  30% {
    transform: translateX(-8px) rotate(-1deg);
    border-color: #ff4a36;
  }

  58% {
    transform: translateX(6px) rotate(1deg);
  }

  100% {
    transform: translateX(0);
  }
}

@keyframes lane-impact {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }

  30% {
    transform: scale(1.04);
    filter: brightness(1.45);
    border-color: #ff4a36;
    box-shadow: inset 0 0 24px rgba(255, 74, 54, 0.56), 0 0 22px rgba(255, 74, 54, 0.42);
  }

  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes burst-pop {
  0% {
    transform: translate(-50%, -50%) scale(0.7);
    opacity: 0;
  }

  22% {
    transform: translate(-50%, -50%) scale(1.06);
    opacity: 1;
  }

  100% {
    transform: translate(-50%, -90%) scale(0.92);
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .game-shell {
    width: min(100vw - 14px, 760px);
    padding: 14px;
    border-width: 5px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scoreboard {
    width: 100%;
  }

  .score-card {
    flex: 1;
  }

  .table {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: minmax(150px, 180px) minmax(0, 1fr);
    align-items: start;
  }

  .primary-action,
  .secondary-action,
  .skill-panel,
  .rules {
    grid-column: 1 / -1;
  }

  .match-board {
    grid-template-columns: minmax(160px, 1fr) 78px minmax(160px, 1fr);
    min-height: 390px;
  }

  .board,
  .center-rail {
    grid-template-rows: repeat(3, minmax(102px, 1fr));
  }

  .column {
    grid-template-columns: repeat(3, minmax(44px, 1fr));
    gap: 7px;
    padding: 8px;
  }
}

@media (max-width: 620px) {
  .lobby-actions {
    grid-template-columns: 1fr;
  }

  .join-row {
    grid-template-columns: 1fr;
  }

  .battle-panel {
    padding: 10px;
  }

  .match-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "enemy-heading"
      "enemy-board"
      "center-rail"
      "player-heading"
      "player-board";
    gap: 8px;
    min-height: 0;
  }

  .board,
  .center-rail {
    gap: 8px;
  }

  .board {
    grid-template-rows: repeat(3, minmax(76px, 1fr));
    padding: 8px;
  }

  .center-rail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 34px 28px 34px;
  }

  .column {
    grid-template-columns: repeat(3, minmax(30px, 1fr));
    gap: 5px;
    padding: 6px;
    border-width: 2px;
  }

  .die {
    width: min(54px, 100%);
    border-radius: 9px;
  }

  .die.big {
    width: 104px;
  }

  .pip {
    width: 10px;
    height: 10px;
  }

  .die.big .pip {
    width: 15px;
    height: 15px;
  }

  .column-score,
  .lane-numbers span {
    min-height: 34px;
    border-width: 2px;
    font-size: 0.82rem;
  }

  .lane-numbers span {
    font-size: 0.68rem;
  }

  .enemy-scores .column-score:nth-child(1),
  .lane-numbers span:nth-child(1),
  .player-scores .column-score:nth-child(1) {
    grid-column: 1;
  }

  .enemy-scores .column-score:nth-child(2),
  .lane-numbers span:nth-child(2),
  .player-scores .column-score:nth-child(2) {
    grid-column: 2;
  }

  .enemy-scores .column-score:nth-child(3),
  .lane-numbers span:nth-child(3),
  .player-scores .column-score:nth-child(3) {
    grid-column: 3;
  }

  .enemy-scores .column-score:nth-child(1),
  .enemy-scores .column-score:nth-child(2),
  .enemy-scores .column-score:nth-child(3) {
    grid-row: 1;
  }

  .lane-numbers span:nth-child(1),
  .lane-numbers span:nth-child(2),
  .lane-numbers span:nth-child(3) {
    grid-row: 2;
  }

  .player-scores .column-score:nth-child(1),
  .player-scores .column-score:nth-child(2),
  .player-scores .column-score:nth-child(3) {
    grid-row: 3;
  }
}

@media (max-width: 460px) {
  .control-panel {
    grid-template-columns: 1fr;
  }

  .battle-panel {
    grid-template-columns: 1fr 1fr;
  }

  .field-heading h2 {
    font-size: 0.92rem;
  }

  .turn-badge {
    min-width: 54px;
    padding: 5px 7px;
  }
}
