:root {
  --ink: #f4efe4;
  --muted: #c9bfae;
  --felt: #146b3a;
  --wood: #8a5a32;
  --brass: #e0b15a;
  --line: rgba(224, 177, 90, 0.35);
  --panel: rgba(18, 28, 24, 0.92);
  --danger: #e15a4a;
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(224, 177, 90, 0.16), transparent 42%),
    linear-gradient(180deg, #1c2c26 0%, #101816 48%, #0c1210 100%);
}

body.playing { overflow: hidden; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, .status { font-weight: 700; margin: 0; letter-spacing: -0.03em; }
h1 { font-size: 46px; }
h2 { font-size: 28px; }
.hidden { display: none !important; }

#app {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
}

.panel, .side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.panel { width: min(440px, 100%); padding: 28px 24px; }
.panel.wide { width: min(720px, 100%); }

.eyebrow {
  margin: 0;
  letter-spacing: 0.22em;
  font-size: 12px;
  font-weight: 700;
  color: var(--brass);
}

.lead, .me, .empty, .hint, .sub { color: var(--muted); line-height: 1.55; }
.lead { margin: 10px 0 0; }
label { display: grid; gap: 6px; margin: 18px 0; font-weight: 700; }
input {
  border: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.45);
  border-radius: 12px;
  padding: 12px 14px;
}
.primary, .ghost {
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid transparent;
}
.primary { background: #c47a2c; color: #1a1208; font-weight: 700; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.45; cursor: default; filter: none; }
.ghost { background: transparent; border-color: var(--line); }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
.row, .create-row, .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row { justify-content: space-between; }
.create-row { margin: 14px 0; }
.create-row input { flex: 1; min-width: 0; margin: 0; }
.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rooms li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: rgba(255, 248, 236, 0.06);
  border-radius: 14px;
  padding: 12px;
}
.rooms li div { display: grid; gap: 2px; }
.rooms button {
  border: 0;
  background: #c47a2c;
  color: #1a1208;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
}
.rooms button:disabled { opacity: 0.45; }
.wait-players, .players { display: grid; gap: 8px; margin: 14px 0; }
.person, .player {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  background: rgba(255, 248, 236, 0.06);
  border-radius: 14px;
  padding: 10px 12px;
}
.player.turn { box-shadow: inset 0 0 0 2px var(--brass); }
.player.you { background: rgba(224, 177, 90, 0.12); }
.player.win { box-shadow: inset 0 0 0 2px #d8ffe4; }
.tag {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1a1208;
  background: var(--brass);
  border-radius: 999px;
  padding: 3px 8px;
}
.rules { margin: 8px 0 16px; }
.rules summary { cursor: pointer; font-weight: 700; }
.rules ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

.play {
  width: min(1180px, 100%);
  height: calc(100dvh - 16px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px 12px;
  align-items: stretch;
}
.status {
  grid-column: 1 / -1;
  min-height: 1.2em;
  font-size: 28px;
  line-height: 1.25;
  color: #fff8ea;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.status.win { color: #f2d48a; }
.status.loss { color: #ffb0a6; }
.table-col { min-width: 0; min-height: 0; display: grid; }
.table-wrap {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
canvas {
  display: block;
  border-radius: 18px;
  touch-action: none;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}
canvas.live { cursor: crosshair; }
canvas.place { cursor: grab; }
.side {
  grid-column: 2;
  grid-row: 2;
  padding: 14px;
  overflow: auto;
  min-height: 0;
}
.side-head { margin-bottom: 6px; }
.sub { min-height: 1.4em; margin: 8px 0; }
.hint { margin: 0 0 12px; font-size: 13px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(28, 20, 12, 0.94);
  color: #fff6ea;
  border-radius: 999px;
  padding: 10px 16px;
  z-index: 5;
  max-width: min(520px, calc(100% - 24px));
}

@media (max-width: 800px), (max-height: 520px) {
  #app { padding: 8px; }
  h1 { font-size: 36px; }
  .play {
    height: calc(100dvh - 8px);
    grid-template-columns: minmax(0, 1fr) 168px;
    gap: 6px;
  }
  .status { font-size: 18px; }
  .side { padding: 8px; }
  .hint { display: none; }
  .player, .person { padding: 6px 8px; }
}

@media (max-width: 640px) and (orientation: portrait) {
  body.playing { overflow: auto; }
  .play {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  .side { grid-column: 1; grid-row: 3; }
  .table-wrap { height: auto; min-height: 42vw; }
}
