:root {
  color-scheme: dark;
  --page: #10251f;
  --panel: #18362c;
  --table: #143e30;
  --line: #557363;
  --text: #f9f2df;
  --muted: #becdc0;
  --accent: #f4c776;
  --ink: #152921;
  --danger: #ffb3a0;
  font: 16px/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--page);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: radial-gradient(ellipse at 18% 0%, #224137 0, transparent 57%), var(--page);
}
h1, h2, p { margin: 0; }
a { color: var(--accent); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.page-width { width: min(100% - 36px, 1152px); margin-inline: auto; }
main:has(.game:not([hidden])) { width: min(100% - 36px, 1360px); }
.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #355747;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 750; text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid #a48350;
  border-radius: 9px;
  color: var(--accent);
  font-size: 1.36rem;
  line-height: 1;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 700;
  text-align: center;
}
.button.primary {
  background: linear-gradient(#f8d28d, #eeb965);
  color: var(--ink);
  box-shadow: inset 0 1px #ffe3aa, 0 3px 0 #8c623c;
}
.button.primary:hover:not(:disabled) { background: #ffda91; }
.button.outline { background: transparent; color: var(--text); border-color: var(--line); }
.button.outline:hover:not(:disabled) { background: #f8f2dd14; border-color: var(--muted); }
.panel {
  background: linear-gradient(155deg, #203e32, var(--panel) 55%);
  border: 1px solid #446654;
  border-radius: 22px;
  box-shadow: inset 0 1px #ffffff0b;
}

.lobby {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  gap: clamp(28px, 7vw, 104px);
  align-items: center;
  min-height: calc(100svh - 68px);
  padding: 52px 0 70px;
}
.intro h1 {
  font: 700 clamp(4rem, 10vw, 8.7rem)/.88 Georgia, serif;
  letter-spacing: -.075em;
  color: var(--text);
}
.intro h1 span { color: var(--accent); }
.intro p { max-width: 34ch; margin-top: 24px; color: var(--muted); font-size: clamp(1rem, 2vw, 1.25rem); }
.tile-art {
  height: 198px;
  max-width: 470px;
  position: relative;
  isolation: isolate;
}
.tile-art::before {
  content: "";
  position: absolute;
  inset: 12% 0 2%;
  background: radial-gradient(ellipse, #c3af724d, transparent 65%);
}
.tile-art .tile {
  --tile-unit: clamp(38px, 6.8vw, 90px);
  position: absolute;
  top: 39px;
  left: 3%;
  transform: rotate(-17deg);
  box-shadow: 0 7px 0 #a38354, 0 11px 0 #644c34, 0 24px 32px #050e0a99;
}
.tile-art .tile:nth-child(2) { top: 79px; left: 31%; transform: rotate(16deg); }
.tile-art .tile:nth-child(3) { top: 32px; left: 62%; transform: rotate(-8deg); }
.entry { padding: clamp(22px, 4vw, 38px); box-shadow: inset 0 1px #c8dec128, 0 18px 70px #07191385; }
.entry h2 { font: 700 clamp(1.65rem, 3vw, 2.15rem)/1.15 Georgia, serif; margin-bottom: 25px; }
.entry label { display: block; margin: 0 0 7px; font-weight: 650; }
.entry input {
  display: block;
  width: 100%;
  color: var(--text);
  background: #102d23;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 13px;
}
.entry input::placeholder { color: #a5b8a5; }
#room-input { text-transform: uppercase; letter-spacing: .12em; }
#room-input::placeholder { text-transform: none; letter-spacing: 0; }
.entry .button { width: 100%; }
.divider { display: flex; align-items: center; gap: 12px; margin: 17px 0; color: var(--muted); }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: #456957; }
.notice { color: var(--accent); margin-top: 12px; }
.notice:empty { display: none; }
.notice.error { color: var(--danger); }

.game { padding: 21px 0 42px; }
.room-head, .hand-head, .table-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.room-heading h1 { font: 700 clamp(2rem, 5vw, 3rem)/1.15 Georgia, serif; margin-top: 5px; }
.room-code { letter-spacing: .08em; color: var(--accent); font-variant-numeric: tabular-nums; }
.back { color: var(--muted); }
.seats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 15px 0 12px; }
.seat { min-width: 0; padding: 11px 15px; border: 1px solid #446654; border-radius: 13px; background: var(--panel); }
.seat.active { border-color: #aa8850; background: linear-gradient(95deg, #314438, #1f392e); box-shadow: inset 3px 0 var(--accent); }
.seat strong { display: block; overflow-wrap: anywhere; }
.seat span { color: var(--muted); }
.room-notice { margin: 0 0 12px; }
.table {
  min-width: 0;
  padding: clamp(14px, 2.4vw, 21px);
  border: 1px solid #688871;
  border-radius: 24px;
  background-color: var(--table);
  background-image:
    radial-gradient(ellipse at 48% 55%, #24634966, transparent 76%),
    repeating-linear-gradient(124deg, #ffffff06 0 1px, transparent 1px 4px);
  box-shadow: inset 0 0 48px #061c1266, 0 14px 38px #0817135e;
}
.table.finished { border-color: #b48e55; }
.table.finished h2 { color: #ffdb98; font-size: clamp(1.55rem, 4vw, 2.25rem); }
.table h2, .hand-panel h2 { font: 700 1.4rem/1.2 Georgia, serif; }
.table h2 { overflow-wrap: anywhere; }
.table-head p { color: var(--muted); margin-top: 6px; }
.table-head p:empty { display: none; }
.boneyard {
  padding: 6px 12px;
  border: 1px solid #6e8d7b;
  border-radius: 99px;
  color: var(--text);
  background: #0a2a2066;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.table.finished .boneyard { opacity: .65; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.edge {
  position: absolute;
  width: var(--edge-width);
  height: var(--board-unit);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px;
  border: 1px dashed #9bb4a4;
  border-radius: 8px;
  color: var(--muted);
  background: #0b2920a8;
  font-size: .75rem;
  font-weight: 650;
}
.edge-value {
  pointer-events: none;
  font: 700 1.15rem/1 Georgia, serif;
}
.edge-label { pointer-events: none; }
.edge:disabled { opacity: .82; }
.edge:enabled { border-color: var(--accent); color: #ffe1a4; background: #463e258a; }
.edge:enabled:hover, .edge.over { border-style: solid; background: #694f2f; }
.board {
  position: relative;
  min-height: 158px;
  margin-top: 16px;
  border: 1px solid #80a99545;
  border-radius: 14px;
  background:
    radial-gradient(#d5efe426 .6px, transparent .6px) 0 0 / 9px 9px,
    #081c153a;
  box-shadow: inset 0 0 26px #061c1242;
}
.board .tile {
  --tile-unit: var(--board-unit);
  position: absolute;
  height: var(--tile-unit);
  min-height: 0;
  border-radius: clamp(5px, 1vw, 9px);
}
.board .tile.vertical {
  flex-direction: column;
  width: var(--tile-unit);
  height: calc(var(--tile-unit) * 2);
}
.board .tile .half {
  min-width: 0;
  min-height: 0;
  padding: calc(var(--tile-unit) * .19);
}
.tile.vertical::after {
  inset: calc(50% - 1px) 9% auto;
  width: auto;
  height: 2px;
  background: linear-gradient(#927248, #c6a777 52%, #fff0c3 53%);
}
.hand-panel { margin-top: 13px; padding: clamp(14px, 2.5vw, 19px); }
.move-hint { color: var(--muted); margin-top: 5px; }
.touch-hint { display: none; }
.hand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px;
  margin-top: 15px;
  border: 1px solid #3b594a;
  border-radius: 11px;
  background: #0a211b8c;
}
.tile {
  --tile-unit: 42px;
  --tile-face: linear-gradient(151deg, #fff6df 3%, #f3e5c9 54%, #dbbf92 100%);
  --pip-ink: #203c32;
  display: inline-flex;
  flex: none;
  align-items: stretch;
  width: calc(var(--tile-unit) * 2);
  min-height: var(--tile-unit);
  padding: 0;
  position: relative;
  overflow: hidden;
  background: var(--tile-face);
  color: var(--pip-ink);
  border: 1px solid #c9a97b;
  border-radius: clamp(6px, 1vw, 12px);
  vertical-align: middle;
  box-shadow:
    inset 0 1px 0 #ffffffc4,
    inset 0 -2px 1px #9f7b4955,
    0 3px 0 #8b6a42,
    0 6px 9px #02100cb3;
}
.tile.double { --tile-face: linear-gradient(151deg, #fff3d4 3%, #eddfbb 54%, #d5b989 100%); }
.half {
  pointer-events: none;
  flex: 1 1 0;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  place-items: center;
  aspect-ratio: 1;
  padding: 11%;
}
.tile::after {
  content: "";
  pointer-events: none;
  position: absolute;
  left: calc(50% - 1px);
  top: 9%;
  bottom: 9%;
  width: 2px;
  background: linear-gradient(90deg, #927248, #c6a777 52%, #fff0c3 53%);
  border-radius: 1px;
}
.pip {
  width: 83%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 60% 78%, #476353, currentColor 63%, #10241d);
  box-shadow: inset 0 1px #0c1715, 0 1px #fff9dbb3;
}
.hand .tile {
  --tile-unit: clamp(37px, 5.8vw, 54px);
  user-select: none;
}
.tile.drag-preview {
  --tile-unit: clamp(37px, 5.8vw, 54px);
  position: fixed;
  z-index: 2;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-7deg);
  box-shadow: inset 0 1px #ffffffc4, 0 4px 0 #8b6a42, 0 12px 18px #020c09b8;
}
.hand .tile:disabled { opacity: .7; }
.hand .tile:enabled { cursor: grab; }
.hand .tile:enabled:hover, .hand .tile[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  transform: translateY(-2px);
}
.hand .tile.dragging { opacity: .52; cursor: grabbing; }
.board .tile.latest { outline: 2px solid #d3a85f; outline-offset: 2px; }

dialog {
  width: min(100% - 32px, 540px);
  padding: 26px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
}
dialog::backdrop { background: #061810ba; }
dialog h2 { font: 700 1.8rem Georgia, serif; }
dialog ol { padding-left: 1.35rem; }
dialog li + li { margin-top: .6rem; }

@media (max-width: 760px) {
  .topbar { height: 65px; }
  .lobby { grid-template-columns: 1fr; gap: 22px; min-height: auto; padding-top: 37px; }
  .intro { position: relative; }
  .intro h1 { font-size: clamp(3.2rem, 13vw, 5.25rem); }
  .intro p { margin-top: 15px; }
  .tile-art { display: none; }
  .hand { gap: 9px; }
}

@media (max-width: 640px) {
  .edge-label { display: none; }
}

@media (min-width: 570px) and (max-width: 760px) {
  .intro { padding-right: 198px; }
  .tile-art { display: block; position: absolute; right: 0; bottom: 5px; width: 194px; height: 90px; }
  .tile-art .tile { --tile-unit: 33px; top: 19px; left: 6px; }
  .tile-art .tile:nth-child(2) { top: 36px; left: 61px; }
  .tile-art .tile:nth-child(3) { top: 23px; left: 122px; }
}

@media (pointer: coarse) {
  .mouse-hint { display: none; }
  .touch-hint { display: inline; }
}
