:root {
  --panel: #cfb875;
  --panel-dark: #342416;
  --ink: #20170e;
  --green: #92ffad;
  --amber: #dfb768;
  --shadow: rgba(0, 0, 0, .48);
  --mobile-browser-bar-reserve: clamp(72px, 12vh, 96px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: #060908;
  color: #f4e8bd;
  font-family: "Microsoft YaHei", SimSun, serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

.scene-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

#tableCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b100f;
  touch-action: none;
}

.crt-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: .34;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.055) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at center, transparent 46%, rgba(0,0,0,.58) 100%);
  mix-blend-mode: soft-light;
}

.mobile-bottom-bleed {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent, rgba(5, 8, 6, .86) 34%, #050806 100%),
    repeating-linear-gradient(90deg, rgba(214, 188, 117, .12) 0 1px, transparent 1px 12px);
  border-top: 1px solid rgba(218, 186, 94, .42);
  box-shadow: 0 -12px 28px rgba(0, 0, 0, .42);
}

.mobile-top-bleed {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  pointer-events: none;
  background:
    linear-gradient(0deg, transparent, rgba(5, 8, 6, .72) 66%, #050806 100%),
    repeating-linear-gradient(90deg, rgba(214, 188, 117, .1) 0 1px, transparent 1px 14px);
  border-bottom: 1px solid rgba(218, 186, 94, .24);
}

.portrait-rotate-hint {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: #f6e8bd;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at center, rgba(32, 55, 43, .96), rgba(4, 7, 6, .98));
}

.portrait-rotate-hint strong,
.portrait-rotate-hint span {
  display: block;
  max-width: 320px;
  text-shadow: 2px 2px 0 #000;
}

.portrait-rotate-hint strong {
  margin-bottom: 10px;
  color: #ffe4a0;
  font-size: 24px;
}

.portrait-rotate-hint span {
  color: rgba(246, 232, 189, .82);
  font-size: 15px;
  line-height: 1.5;
}

.hud,
.dialogue,
.match-log,
.play-status,
.action-bar {
  position: absolute;
  z-index: 10;
  border: 2px solid #2d2114;
  background:
    linear-gradient(145deg, rgba(255,255,255,.18), transparent 38%),
    linear-gradient(#dfcb94, #b99b5d);
  box-shadow: inset -8px -10px 0 rgba(54,37,20,.14), 0 8px 0 rgba(0,0,0,.28);
  color: var(--ink);
}

.hud header,
.dialogue b {
  display: block;
  padding: 8px 10px;
  color: #ffe8a4;
  font-weight: 900;
  background: linear-gradient(135deg, #382817 0 56%, #604729 56% 100%);
  text-shadow: 1px 1px 0 #000;
}

.api-dock-3d {
  position: absolute;
  z-index: 12;
  top: 18px;
  right: 18px;
  width: min(300px, calc(100vw - 36px));
  color: #ead58e;
  font-family: "Microsoft YaHei", SimSun, serif;
}

.api-toggle-3d,
.api-body-3d button {
  border: 2px solid rgba(71, 49, 24, .95);
  background: linear-gradient(#d8b762, #8d632d);
  color: #1b1008;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(27, 16, 8, .72);
}

.api-toggle-3d {
  float: right;
  padding: 8px 12px;
}

.api-body-3d {
  clear: both;
  margin-top: 42px;
  padding: 12px;
  border: 2px solid rgba(117, 80, 44, .85);
  background: rgba(11, 18, 14, .9);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .38);
}

.api-dock-3d.is-collapsed .api-body-3d {
  display: none;
}

.guide-toggle {
  position: absolute;
  z-index: 13;
  top: 18px;
  left: 18px;
  min-height: 36px;
  padding: 8px 13px;
  border: 2px solid rgba(71, 49, 24, .95);
  background:
    linear-gradient(145deg, rgba(255,255,255,.18), transparent 38%),
    linear-gradient(#d8b762, #8d632d);
  color: #1b1008;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(27, 16, 8, .72), 0 12px 26px rgba(0, 0, 0, .28);
}

.guide-panel {
  position: absolute;
  z-index: 14;
  top: 62px;
  left: 18px;
  width: min(430px, calc(100vw - 36px));
  max-height: calc(100vh - 92px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  color: #f1dfaa;
  border: 2px solid rgba(117, 80, 44, .9);
  background:
    linear-gradient(145deg, rgba(255,255,255,.08), transparent 44%),
    linear-gradient(180deg, rgba(21, 28, 22, .97), rgba(9, 14, 11, .96));
  box-shadow: 0 18px 42px rgba(0, 0, 0, .48), inset 0 0 0 1px rgba(215, 180, 100, .14);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity .16s steps(3, end), transform .16s steps(3, end);
}

.guide-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.guide-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px 11px;
  border-bottom: 1px solid rgba(218, 186, 94, .28);
  background: linear-gradient(90deg, rgba(71, 47, 24, .72), rgba(21, 28, 22, .18));
}

.guide-panel header span {
  display: block;
  color: #d8b762;
  font-size: 12px;
  font-weight: 900;
}

.guide-panel header strong {
  display: block;
  margin-top: 2px;
  color: #fff0b8;
  font-size: 18px;
}

.guide-panel header button,
.guide-tabs button {
  border: 1px solid #4d351a;
  color: #1b1008;
  background: #cda75a;
  font-weight: 900;
  cursor: pointer;
}

.guide-panel header button {
  min-height: 30px;
  padding: 4px 10px;
}

.guide-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px 0;
}

.guide-tabs button {
  min-height: 34px;
  color: #f4d98d;
  background: #17110c;
  box-shadow: inset 0 0 10px rgba(0,0,0,.42);
}

.guide-tabs button.is-active {
  color: #1b1008;
  background: linear-gradient(#e1c173, #ad7935);
}

.guide-body {
  min-height: 0;
  margin: 10px 12px 12px;
  padding: 12px 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cda75a rgba(42, 28, 16, .48);
  border: 1px solid rgba(218, 186, 94, .24);
  background: rgba(6, 10, 8, .54);
  line-height: 1.55;
}

.guide-body::-webkit-scrollbar {
  width: 7px;
}

.guide-body::-webkit-scrollbar-track {
  background: rgba(42, 28, 16, .48);
}

.guide-body::-webkit-scrollbar-thumb {
  background: linear-gradient(#e0c171, #a87935);
  border: 1px solid #3b2814;
}

.guide-page {
  display: none;
}

.guide-page.is-active {
  display: block;
}

.guide-page h2,
.guide-page h3,
.guide-page p,
.guide-page ol,
.guide-page ul {
  margin-top: 0;
}

.guide-page h2 {
  margin-bottom: 10px;
  color: #fff0b8;
  font-size: 20px;
}

.guide-page h3 {
  margin: 18px 0 8px;
  color: #d8ffb8;
  font-size: 15px;
}

.guide-page p,
.guide-page li {
  color: rgba(245, 225, 171, .9);
  font-size: 14px;
}

.guide-page ol,
.guide-page ul {
  display: grid;
  gap: 6px;
  padding-left: 20px;
}

.api-body-3d p {
  margin: 0 0 8px;
  color: rgba(234, 213, 142, .78);
  font-size: 12px;
  line-height: 1.45;
}

.api-body-3d label {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: rgba(234, 213, 142, .9);
}

.api-body-3d input,
.api-body-3d select {
  width: 100%;
  margin-top: 5px;
  border: 1px solid rgba(117, 80, 44, .9);
  background: #0d1712;
  color: #ead58e;
  padding: 8px;
}

.api-body-3d button {
  margin-top: 10px;
  padding: 7px 12px;
}

.hud-left {
  top: 18px;
  left: 18px;
  width: min(270px, 17vw);
  min-width: 230px;
  bottom: 96px;
}

.quiet-hud {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
}

.hud-right {
  top: 18px;
  right: 18px;
  width: min(340px, 23vw);
  min-width: 280px;
  max-height: calc(100vh - 128px);
  transition: transform .18s steps(2, end), opacity .18s steps(2, end);
}

.hud-right.is-collapsed {
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 24px));
}

.round-readout {
  margin: 14px;
  padding: 14px;
  background: #101914;
  border: 2px solid #24392d;
  color: var(--green);
  font-family: "Lucida Console", monospace;
  box-shadow: inset 0 0 20px rgba(0,0,0,.72);
}

.round-readout b {
  display: block;
  margin-top: 4px;
  font-size: 34px;
  text-align: right;
  text-shadow: 0 0 12px rgba(128,255,154,.75);
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 14px;
  padding: 10px;
  border: 1px solid #6a4d28;
  background: #f0dda2;
  font-size: 18px;
}

.score-row strong {
  color: #7a251c;
  font-family: "Lucida Console", monospace;
}

.log-box {
  margin: 14px;
  border: 1px solid #6a4d28;
  background: rgba(255,247,207,.64);
}

.log-box b {
  display: block;
  padding: 8px;
  border-bottom: 1px solid #6a4d28;
}

.log-box p {
  margin: 0;
  padding: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.rule-page {
  margin: 14px;
  padding: 14px;
  border: 1px solid #6a4d28;
  background: rgba(255,247,207,.72);
}

.rule-page h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.rule-page p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.45;
}

.rule-page article {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #806033;
  background: #f3e1a9;
}

.dialogue {
  left: 50%;
  top: 138px;
  width: min(660px, 52vw);
  min-width: 360px;
  transform: translateX(-50%);
  border: 0;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.36) 16%, rgba(0,0,0,.36) 84%, transparent);
  box-shadow: none;
  color: #f6e8bd;
  text-align: center;
  text-shadow: 2px 2px 0 #000, 0 0 10px rgba(0,0,0,.8);
}

.dialogue p {
  margin: 0;
  padding: 6px 18px;
  line-height: 1.45;
  font-size: 16px;
}

.match-log {
  top: 96px;
  left: 24px;
  width: 312px;
  max-height: calc(100vh - 150px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) rotate(-1deg);
  transition: opacity .16s steps(3, end), transform .16s steps(3, end);
}

.match-log.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) rotate(-1deg);
}

.match-log header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0 10px;
  border-bottom: 2px solid rgba(68, 43, 18, .52);
  font-weight: 900;
}

.match-log header button {
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid #3b2814;
  color: var(--ink);
  background: #cda75a;
  font-weight: 900;
  cursor: pointer;
}

.match-log ol {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0 8px 2px 0;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cda75a rgba(42, 28, 16, .48);
}

.match-log ol::-webkit-scrollbar {
  width: 7px;
}

.match-log ol::-webkit-scrollbar-track {
  background: rgba(42, 28, 16, .48);
  border-left: 1px solid rgba(74, 50, 29, .62);
}

.match-log ol::-webkit-scrollbar-thumb {
  background: linear-gradient(#e0c171, #a87935);
  border: 1px solid #3b2814;
}

.match-log li {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  padding: 8px;
  border: 1px solid rgba(74, 50, 29, .62);
  background: rgba(255, 244, 198, .56);
  font-size: 14px;
}

.match-log li span {
  color: #402712;
}

.action-bar {
  left: 31vw;
  right: 13vw;
  bottom: 16px;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-color: rgba(53, 38, 23, .78);
  background:
    linear-gradient(145deg, rgba(255,255,255,.1), transparent 44%),
    linear-gradient(180deg, rgba(48, 34, 21, .9), rgba(24, 19, 14, .92));
  box-shadow: 0 8px 18px var(--shadow), inset 0 0 0 1px rgba(215, 180, 100, .18);
}

.play-status {
  left: 50%;
  right: auto;
  width: min(520px, 52vw);
  bottom: 84px;
  display: flex;
  justify-content: center;
  transform: translateX(-50%);
  border: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.play-readout {
  display: grid;
  justify-items: center;
  gap: 5px;
  width: 100%;
  min-width: 260px;
  min-height: 48px;
  padding: 9px 18px;
  color: #d9ffb0;
  background:
    linear-gradient(90deg, transparent, rgba(9, 16, 12, .76) 12%, rgba(9, 16, 12, .76) 88%, transparent);
  border-block: 1px solid rgba(211, 184, 104, .34);
  box-shadow: 0 8px 18px rgba(0,0,0,.32);
  font-family: "Microsoft YaHei", SimSun, serif;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.22;
  text-shadow: 2px 2px 0 #000, 0 0 10px rgba(0,0,0,.78);
}

.play-readout span,
.play-readout b {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-readout b {
  color: #ffd37a;
  font-weight: 900;
  font-size: 14px;
}

.play-readout.is-warning {
  border-color: rgba(255, 179, 91, .52);
  color: #ffe5a2;
}

.quick-actions {
  position: absolute;
  z-index: 10;
  left: 3vw;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-bar button,
.action-bar input,
.quick-actions button {
  min-height: 36px;
  border: 1px solid #3b2814;
}

.action-bar button,
.quick-actions button {
  min-width: 72px;
  padding: 8px 12px;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(255,255,255,.18), transparent 38%),
    linear-gradient(#d6bc75, #b88f45);
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset -4px -5px 0 rgba(54,37,20,.18), 0 5px 0 rgba(0,0,0,.32);
}

.quick-actions .restart-action {
  color: #ffe8b8;
  background:
    linear-gradient(145deg, rgba(255,255,255,.12), transparent 42%),
    linear-gradient(#7e3b2b, #4b241a);
  border-color: #2f1710;
  text-shadow: 1px 1px 0 #100806;
}

.action-bar .primary {
  color: #f6fff0;
  background: linear-gradient(#3b8b6b, #24644d);
}

.action-bar input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  color: #f7e8bd;
  background: #121812;
  border-color: #45593d;
  box-shadow: inset 0 0 18px rgba(0,0,0,.72);
}

.action-bar input::placeholder {
  color: rgba(247, 232, 189, .62);
}

.mode-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 132px;
  min-height: 36px;
  padding: 3px;
  border: 1px solid #3b2814;
  background: #18120d;
  box-shadow: inset 0 0 12px rgba(0,0,0,.5);
}

.mode-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  background: #d4ad5d;
  box-shadow: inset -4px -4px 0 rgba(67,42,17,.16);
  transition: transform .16s steps(3, end);
}

.mode-switch:has(input[value="chat"]:checked)::before {
  transform: translateX(100%);
}

.mode-switch label {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-weight: 900;
  color: #f4d98d;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-switch input:checked + span {
  color: var(--ink);
}

@media (max-width: 920px) {
  .hud-left,
  .hud-right,
  .dialogue {
    display: none;
  }

  .quick-actions,
  .play-status,
  .action-bar {
    left: 12px;
    right: 12px;
  }

  .play-status {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 146px;
    transform: none;
  }

  .play-readout {
    width: min(520px, calc(100vw - 24px));
    min-width: 0;
    font-size: 15px;
  }

  .quick-actions {
    bottom: 94px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hud-left,
  .hud-right,
  .api-dock-3d,
  .match-log {
    display: none;
  }

  .mobile-bottom-bleed {
    display: block;
    height: calc(var(--mobile-browser-bar-reserve) + 52px + env(safe-area-inset-bottom));
  }

  .mobile-top-bleed {
    display: block;
    height: calc(48px + env(safe-area-inset-top));
  }

  .dialogue {
    display: block;
    top: calc(8px + env(safe-area-inset-top));
    left: 50%;
    width: min(620px, calc(100vw - 260px));
    min-width: 240px;
    z-index: 11;
    background: linear-gradient(90deg, transparent, rgba(0,0,0,.42) 12%, rgba(0,0,0,.42) 88%, transparent);
  }

  .dialogue p {
    max-height: 42px;
    padding: 5px 14px;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.35;
  }

  .guide-toggle {
    top: 8px;
    left: 10px;
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
    box-shadow: 0 3px 0 rgba(27, 16, 8, .72), 0 9px 18px rgba(0, 0, 0, .26);
  }

  .guide-panel {
    top: 46px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 116px);
  }

  .guide-panel header {
    padding: 9px 10px 8px;
  }

  .guide-panel header strong {
    font-size: 16px;
  }

  .guide-tabs {
    padding: 8px 9px 0;
  }

  .guide-tabs button {
    min-height: 30px;
    font-size: 13px;
  }

  .guide-body {
    margin: 8px 9px 9px;
    padding: 9px 11px;
  }

  .guide-page p,
  .guide-page li {
    font-size: 13px;
  }

  .quick-actions {
    left: calc(8px + env(safe-area-inset-left));
    right: auto;
    bottom: calc(var(--mobile-browser-bar-reserve) + env(safe-area-inset-bottom));
    width: min(32vw, 238px);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .quick-actions button {
    min-width: 0;
    min-height: 44px;
    padding: 8px 8px;
    font-size: 13px;
    box-shadow: inset -3px -4px 0 rgba(54,37,20,.18), 0 3px 0 rgba(0,0,0,.32);
  }

  .action-bar {
    left: auto;
    right: calc(8px + env(safe-area-inset-right));
    bottom: calc(var(--mobile-browser-bar-reserve) + env(safe-area-inset-bottom));
    width: min(46vw, 360px);
    min-height: 52px;
    gap: 6px;
    padding: 6px;
    box-shadow: 0 4px 10px var(--shadow), inset 0 0 0 1px rgba(215, 180, 100, .18);
  }

  .action-bar button,
  .action-bar input {
    min-height: 44px;
    font-size: 13px;
  }

  .action-bar .primary {
    min-width: 52px;
    padding: 6px 8px;
  }

  .action-bar input {
    padding: 6px 8px;
    font-size: 16px;
  }

  .mode-switch {
    min-width: 94px;
    min-height: 32px;
    font-size: 12px;
  }

  .play-status {
    left: 50%;
    right: auto;
    width: min(42vw, 360px);
    bottom: calc(var(--mobile-browser-bar-reserve) + 6px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }

  .play-readout {
    min-width: 0;
    min-height: 34px;
    padding: 6px 12px;
    font-size: 13px;
  }
}

@media (orientation: portrait) and (max-width: 920px) {
  .portrait-rotate-hint {
    display: grid;
  }
}
