:root {
  --ink: #1c140f;
  --cream: #f6efe2;
  --gold: #e7c98a;
  --felt: #145443;
  --felt-deep: #0c332c;
  --wood: #3a2418;
  --loss: #c4493a;
  --good: #d8f3c7;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--cream);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(231, 201, 138, 0.16), transparent 42%),
    radial-gradient(ellipse at 50% 120%, #1a0e09, #070605 60%);
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
#lamp {
  pointer-events: none;
  position: fixed;
  inset: 0 0 auto;
  height: 180px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 214, 140, 0.18), transparent 70%);
}
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px 0;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 22px; letter-spacing: 0.04em; }
.brand em { font-style: normal; color: #cbbba6; font-size: 13px; }
.mark {
  width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--cream); color: var(--ink); font-family: Georgia, serif; font-weight: 700;
}
#meta { margin-left: auto; color: var(--gold); letter-spacing: 0.14em; font-size: 14px; }
header button, .actions button, .gate button, .sheet button, dialog button {
  border: 1px solid rgba(231, 201, 138, 0.45);
  background: rgba(255, 244, 220, 0.08);
  border-radius: 999px;
  padding: 8px 14px;
}
header button:hover, .actions button:hover, .gate button:hover, .sheet button:hover { background: rgba(255, 244, 220, 0.16); }
main { padding: 8px 14px 16px; }
.gate, .lobby {
  max-width: 760px;
  margin: 28px auto;
  background: rgba(28, 18, 12, 0.78);
  border: 1px solid rgba(231, 201, 138, 0.25);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.gate h1, .lobby h1, dialog h2 { font-family: Georgia, serif; font-weight: 500; margin: 0 0 8px; }
.lede { color: #e6d8c8; line-height: 1.5; }
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
label { display: grid; gap: 6px; font-size: 13px; color: #d9cbb8; flex: 1; min-width: 180px; }
input {
  background: #120c09;
  border: 1px solid rgba(246, 239, 226, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
}
.tables { display: grid; gap: 8px; margin-top: 8px; }
.table-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}
.table-row b { display: block; letter-spacing: 0.12em; }
.table-row span, .table-row em { display: block; color: #cbbba6; font-style: normal; font-size: 13px; }
.gate button.primary, .lobby button.primary, .actions button.primary {
  background: var(--gold);
  color: var(--ink);
  border-color: transparent;
  font-weight: 700;
}
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0; }
.slot {
  min-height: 92px;
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(246, 239, 226, 0.2);
}
.slot b { display: block; margin-bottom: 6px; }
.slot span { color: #cbbba6; font-size: 13px; }
.arena {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 12px;
  width: min(1180px, 100%);
  margin: 0 auto;
  align-items: start;
}
.felt-wrap { display: grid; gap: 8px; justify-items: center; min-width: 0; width: 100%; }
.mid {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 104px;
  gap: 8px;
  align-items: center;
}
.seat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.seat.bottom { width: 100%; }
.rt { width: 74px; height: 22px; }
.who { font-size: 13px; color: #f0e2cf; display: flex; gap: 6px; align-items: center; }
.badge { font-size: 11px; letter-spacing: 0.06em; color: var(--ink); background: var(--gold); border-radius: 999px; padding: 1px 6px; }
.turn { outline: 2px solid var(--gold); border-radius: 12px; }
.felt {
  min-width: 0;
  width: 100%;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.05), transparent 55%),
    linear-gradient(180deg, var(--felt), var(--felt-deep));
  border-radius: 22px;
  border: 6px solid #5a3824;
  box-shadow: inset 0 0 0 3px #2a170f, 0 16px 40px rgba(0,0,0,0.35);
  padding: 8px 10px 8px;
  position: relative;
}
.chain {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  width: 100%;
  max-width: 100%;
  min-height: 84px;
  align-items: center;
  padding: 2px 2px 16px;
}
.ends { display: flex; justify-content: space-between; gap: 8px; width: 100%; }
.ends button {
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.2);
  padding: 8px 12px;
}
.ends button.hot { background: var(--gold); color: var(--ink); border-color: transparent; }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; min-height: 96px; width: 100%; }
.mini { min-height: 0; flex-wrap: wrap; justify-content: center; max-width: 150px; }
.mini .bone { width: 32px; height: 60px; box-shadow: 0 4px 0 #c9b79a; }
.mini .pip { width: 5px; height: 5px; }
.bone {
  width: 46px;
  height: 88px;
  border-radius: 8px;
  background: linear-gradient(#fffaf2, #efe4d2);
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 0 #c9b79a, 0 12px 18px rgba(0,0,0,0.28);
  flex: 0 0 auto;
  position: relative;
}
.bone.flat { flex-direction: row; width: 92px; height: 48px; }
.bone.dbl { width: 48px; height: 92px; }
.bone .half { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 5px; }
.bone.flat .half { padding: 4px; }
.bone .half + .half { border-top: 1px solid rgba(0,0,0,0.25); }
.bone.flat .half + .half { border-top: 0; border-left: 1px solid rgba(0,0,0,0.25); }
.pip { width: 8px; height: 8px; border-radius: 50%; background: #161616; place-self: center; }
.pip.red { background: #b42318; }
button.tile {
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
}
button.tile.on .bone { transform: translateY(-10px); box-shadow: 0 14px 0 #e7c98a, 0 18px 18px rgba(0,0,0,0.3); }
button.tile:disabled { cursor: default; }
.back {
  width: 42px; height: 68px; border-radius: 7px;
  background:
    repeating-linear-gradient(45deg, #2e6f62, #2e6f62 4px, #1d4f46 4px, #1d4f46 8px);
  border: 2px solid #f6efe2;
  box-shadow: 0 6px 0 #0b2a24;
}
.backs { display: flex; gap: 4px; }
.log {
  background: rgba(0,0,0,0.28);
  border-radius: 16px;
  padding: 10px 12px;
  max-height: 280px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.45;
  color: #eadfce;
}
.log p { margin: 0 0 6px; }
.dock {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  width: min(920px, 100%);
}
.actions { display: flex; gap: 8px; align-items: center; }
.hint { color: #f0d7a2; font-size: 14px; min-height: 1.2em; }
.rt { width: 74px; height: 22px; }
.rt text { font-size: 10px; fill: #c4493a; font-weight: 700; }
.sheet {
  margin-top: 8px;
  background: rgba(18, 10, 7, 0.92);
  border: 1px solid rgba(231, 201, 138, 0.3);
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  width: min(920px, 100%);
}
.sheet table { border-collapse: collapse; font-size: 14px; }
.sheet td { padding: 3px 10px 3px 0; }
.up { color: #ffb4a8; }
.down { color: #b7e4a4; }
#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #3a1612;
  color: #ffd9d3;
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; }
dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--cream);
}
dialog article {
  width: min(640px, 92vw);
  background: #24160f;
  border-radius: 20px;
  padding: 22px;
  border: 1px solid rgba(231, 201, 138, 0.3);
}
dialog ol { padding-left: 18px; line-height: 1.45; }
dialog::backdrop { background: rgba(0,0,0,0.55); }
#toggle-info { display: none; }
#rotate-lock {
  display: none;
}
.rotate-phone {
  width: 72px;
  height: 120px;
  border: 3px solid var(--gold);
  border-radius: 12px;
  margin-bottom: 16px;
  animation: turn-phone 1.6s ease-in-out infinite;
}
@keyframes turn-phone {
  0%, 20% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(90deg); }
}
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-lock {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 80;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 28px;
    text-align: center;
    background: #120c09;
  }
  #rotate-lock p { margin: 0; color: #e6d8c8; max-width: 18rem; }
}
@media (max-width: 860px) {
  .slots { grid-template-columns: 1fr 1fr; }
  .arena { grid-template-columns: 1fr; }
  .mid { grid-template-columns: 92px 1fr 92px; }
  header { padding-inline: 12px; }
  .log { max-height: 140px; }
  .dock, .sheet { flex-direction: column; align-items: stretch; }
}
@media (max-height: 520px) {
  html, body { height: 100%; overflow: hidden; }
  body { min-height: 0; }
  #lamp { display: none; }
  #toggle-info { display: inline-block; }
  header { padding: 4px 8px; gap: 8px; }
  .brand em { display: none; }
  .brand strong { font-size: 16px; }
  .mark { width: 28px; height: 28px; border-radius: 8px; }
  main { height: calc(100dvh - 38px); padding: 4px 8px 6px; overflow: hidden; }
  .lede, .log, .hint { display: none; }
  body.info-open .lede,
  body.info-open .hint { display: block; }
  body.info-open .log { display: block; }
  .gate, .lobby {
    margin: 0 auto;
    padding: 10px 12px;
    max-height: 100%;
    overflow: auto;
  }
  .arena {
    position: relative;
    height: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .log {
    position: absolute;
    z-index: 6;
    left: 0;
    right: 0;
    top: 0;
    max-height: 46%;
  }
  .felt-wrap {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 2px;
  }
  .mid {
    height: 100%;
    min-height: 0;
    grid-template-columns: 68px minmax(0, 1fr) 68px;
    gap: 4px;
  }
  .seat .rt { display: none; }
  .who {
    font-size: 11px;
    max-width: 68px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .seat.bottom .who { max-width: none; }
  .felt {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 4px 6px;
    border-width: 4px;
    border-radius: 16px;
  }
  .chain { flex: 1; min-height: 0; padding-bottom: 8px; }
  .ends button { padding: 4px 8px; font-size: 12px; }
  .bone.flat { width: 64px; height: 34px; }
  .bone.dbl { width: 34px; height: 64px; }
  .hand { min-height: 0; padding: 0; gap: 4px; }
  .seat.bottom .bone { width: 34px; height: 64px; box-shadow: 0 4px 0 #c9b79a; }
  .pip { width: 6px; height: 6px; }
  .dock { gap: 4px; }
  .sheet { margin-top: 4px; padding: 8px; max-height: 28%; overflow: auto; }
}
