:root {
  --bg0: #140e08;
  --bg1: #24180f;
  --wood: #8b5a2b;
  --wood-deep: #5c3a1a;
  --line: #2a1a0c;
  --ink: #1c120a;
  --cream: #f3e6c8;
  --red: #c0392b;
  --red-deep: #8e1f14;
  --black: #1f1a16;
  --gold: #d4a84b;
  --gold-soft: #e8c97a;
  --mist: rgba(243, 230, 200, 0.12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --font-body: "Noto Serif SC", "Songti SC", serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, #3a2716 0%, transparent 55%),
    radial-gradient(90% 60% at 100% 100%, #2a160c 0%, transparent 50%),
    linear-gradient(165deg, var(--bg1), var(--bg0));
  color: var(--cream);
  font-family: var(--font-body);
  user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.25) 2px,
      rgba(0, 0, 0, 0.25) 3px
    );
}

.app {
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding:
    calc(12px + var(--safe-t))
    14px
    calc(10px + var(--safe-b))
    14px;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--gold-soft);
  background:
    radial-gradient(circle at 35% 30%, #6b4224, #2b180c);
  border: 1.5px solid var(--gold);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.18em;
  line-height: 1.1;
  color: var(--cream);
}

.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  letter-spacing: 0.35em;
  color: rgba(232, 201, 122, 0.7);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(212, 168, 75, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: var(--cream);
  font-size: 18px;
  cursor: pointer;
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
}

.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(243, 230, 200, 0.12);
  font-size: 14px;
}

.turn-pill .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.turn-pill .dot.red { background: var(--red); }
.turn-pill .dot.black { background: #cfc5b3; }

.mode-label {
  font-size: 12px;
  color: rgba(243, 230, 200, 0.55);
  letter-spacing: 0.08em;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

#board {
  width: min(100%, calc(100dvh - 230px));
  height: auto;
  max-height: 100%;
  touch-action: none;
  border-radius: 10px;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(212, 168, 75, 0.18);
  background: #9a6230;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border: 1px solid rgba(243, 230, 200, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--cream);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, background 0.15s ease;
}

.tool span { font-size: 18px; line-height: 1; }
.tool small { font-size: 11px; opacity: 0.75; letter-spacing: 0.05em; }
.tool:active { transform: scale(0.96); }
.tool.primary {
  background: linear-gradient(180deg, #b33a2c, #7d1e14);
  border-color: rgba(255, 180, 140, 0.25);
}
.tool[hidden] { display: none; }

.sheet[hidden], .overlay[hidden], .toast[hidden] { display: none !important; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 2, 0.62);
  backdrop-filter: blur(4px);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: 22px 18px calc(22px + var(--safe-b));
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, #2c1d12, #1a120b);
  border-top: 1px solid rgba(212, 168, 75, 0.3);
  animation: slide-up 0.28s ease;
}

@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.sheet-panel h2 {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.12em;
  font-size: 22px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: rgba(243, 230, 200, 0.72);
}

.field select {
  appearance: none;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(243, 230, 200, 0.16);
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
  font: inherit;
  font-size: 15px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 18px;
  font-size: 14px;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.08em;
  cursor: pointer;
  color: var(--cream);
  background: linear-gradient(180deg, #b33a2c, #7d1e14);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(243, 230, 200, 0.14);
}

.install-tip {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(243, 230, 200, 0.5);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 12, 6, 0.92);
  border: 1px solid rgba(212, 168, 75, 0.35);
  color: var(--gold-soft);
  font-size: 13px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  animation: fade-toast 0.25s ease;
}

@keyframes fade-toast {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(8, 5, 2, 0.72);
  padding: 24px;
}

.result-card {
  width: min(320px, 100%);
  text-align: center;
  padding: 28px 22px;
  border-radius: 18px;
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(212, 168, 75, 0.18), transparent 55%),
    linear-gradient(180deg, #302014, #1a110a);
  border: 1px solid rgba(212, 168, 75, 0.35);
  animation: rise 0.35s ease;
}

.result-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  letter-spacing: 0.16em;
  color: var(--gold-soft);
}

.result-card p {
  margin: 0 0 20px;
  color: rgba(243, 230, 200, 0.65);
  font-size: 14px;
}

@media (min-width: 700px) {
  .app { padding-top: 24px; }
  #board { width: min(460px, calc(100dvh - 250px)); }
}
