:root {
  --background-top: #173c34;
  --background-middle: #0b2420;
  --background-bottom: #171217;
  --surface: #102c25;
  --surface-muted: #0d201c;
  --surface-warm: #351b17;
  --stroke-green: #244c3e;
  --stroke-muted: #2b473e;
  --stroke-warm: #a24734;
  --gold-top: #ffe38e;
  --gold-bottom: #d49a2d;
  --red-top: #e2543e;
  --red-bottom: #90211e;
  --cup-top: #b43b2e;
  --cup-middle: #6f1919;
  --cup-bottom: #2b0d12;
  --text-primary: #fff7e8;
  --text-secondary: #b9b09e;
  --text-muted: #9f9788;
  --dice-face: #fffaf0;
  --dice-pip: #161616;
  --panel-radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #07110f;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 10%, rgba(226, 84, 62, 0.16), transparent 28%),
    radial-gradient(circle at 86% 0%, rgba(255, 227, 142, 0.12), transparent 24%),
    linear-gradient(145deg, var(--background-top), var(--background-middle) 56%, var(--background-bottom));
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent 78%);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
}

a {
  color: inherit;
}

.app-shell {
  position: relative;
  width: min(100%, 480px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 16px calc(22px + env(safe-area-inset-bottom));
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.top-bar h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: 25px;
  font-weight: 850;
  line-height: 1.12;
  letter-spacing: 0;
}

.top-bar p {
  margin: 7px 0 0;
  color: #adc2b1;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.icon-button {
  min-width: 38px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #735428;
  border-radius: var(--panel-radius);
  background: #3b2b14;
  color: #fff5df;
  font-size: 12px;
  font-weight: 850;
  line-height: 30px;
}

.sound-button {
  min-width: 58px;
  border-color: #7c4a38;
  background: #37201b;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin: 26px -16px 0 0;
  padding: 0 16px 4px 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.mode-tabs::-webkit-scrollbar {
  display: none;
}

.mode-tab {
  flex: 0 0 auto;
  min-width: 86px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid #315747;
  border-radius: var(--panel-radius);
  background: #17382f;
  color: #dad3c4;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mode-tab.is-active {
  border-color: transparent;
  background: linear-gradient(145deg, var(--gold-top), var(--gold-bottom));
  color: #24160b;
}

.mode-tab:disabled,
.primary-button:disabled,
.count-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.hero-panel,
.result-panel,
.controls-panel,
.static-card {
  border: 1px solid var(--stroke-green);
  border-radius: var(--panel-radius);
  background: rgba(16, 44, 37, 0.92);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.24);
}

.hero-panel {
  position: relative;
  min-height: 270px;
  margin-top: 20px;
  padding: 22px 16px 16px;
  overflow: hidden;
  text-align: center;
}

.tray-preview {
  position: absolute;
  left: 50%;
  top: 82px;
  display: flex;
  width: min(88%, 292px);
  min-height: 86px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 180ms ease;
}

.hero-panel.has-result.is-open .tray-preview {
  opacity: 1;
}

.hero-panel.has-result.is-closed .tray-preview {
  opacity: 0.22;
  filter: blur(1px);
}

.cup-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  width: 170px;
  height: 190px;
  margin: 0 auto;
  touch-action: none;
  cursor: pointer;
  transform: translateY(var(--cup-offset, 0px));
  transition: transform 180ms ease;
}

.cup-wrap.is-dragging {
  transition: none;
}

.cup-wrap.is-rolling {
  animation: shakeCup 1500ms ease-in-out both;
}

.dice-cup {
  position: relative;
  width: 140px;
  height: 170px;
}

.dice-cup::before {
  position: absolute;
  left: 14px;
  top: 28px;
  width: 112px;
  height: 116px;
  border-radius: 38px 38px 28px 28px / 22px 22px 34px 34px;
  content: "";
  background: linear-gradient(145deg, var(--cup-top), var(--cup-middle) 55%, var(--cup-bottom));
  box-shadow: inset 12px 0 22px rgba(255, 210, 142, 0.12), inset -14px -20px 22px rgba(0, 0, 0, 0.3);
}

.dice-cup::after {
  position: absolute;
  left: 18px;
  bottom: 20px;
  width: 104px;
  height: 34px;
  border-radius: 50%;
  content: "";
  background: linear-gradient(180deg, #c65a43, #2f1111 78%);
  box-shadow: 0 17px 18px rgba(0, 0, 0, 0.34);
}

.dice-cup span {
  position: absolute;
  left: 38px;
  top: 33px;
  width: 64px;
  height: 18px;
  border-radius: 50%;
  background: #8f2b25;
  box-shadow: 0 22px 0 -7px rgba(241, 179, 109, 0.58);
}

.hero-status {
  position: relative;
  z-index: 3;
  min-height: 20px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
}

.controls-panel {
  margin-top: 18px;
  padding: 14px;
  background: rgba(13, 32, 28, 0.92);
}

.control-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.control-hint {
  color: var(--text-muted);
  font-size: 11px;
}

.count-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.count-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.count-button {
  height: 36px;
  border: 1px solid var(--stroke-muted);
  border-radius: var(--panel-radius);
  background: #14352d;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 850;
}

.count-button.is-active {
  border-color: transparent;
  background: linear-gradient(145deg, var(--gold-top), var(--gold-bottom));
  color: #24160b;
}

.fixed-mode-copy {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.primary-button,
.primary-link {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 16px;
  border-radius: var(--panel-radius);
  background: linear-gradient(145deg, var(--gold-top), var(--gold-bottom));
  color: #24160b;
  box-shadow: 0 14px 24px rgba(18, 13, 4, 0.28);
  font-size: 17px;
  font-weight: 900;
  line-height: 56px;
  text-align: center;
  text-decoration: none;
}

.result-panel {
  min-height: 178px;
  margin-top: 18px;
  padding: 18px 14px;
  transition: opacity 180ms ease, filter 180ms ease;
}

.result-panel.is-covered {
  pointer-events: none;
  user-select: none;
}

.result-panel.is-covered .covered-result {
  min-height: 124px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.empty-state {
  display: grid;
  grid-template-columns: repeat(2, 60px);
  justify-content: center;
  gap: 12px 38px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state p {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 700;
}

.placeholder-dice {
  width: 60px;
  aspect-ratio: 1;
  border: 2px solid #d6cbbc;
  border-radius: 10px;
  background: var(--dice-face);
  opacity: 0.16;
}

.dice-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.dice-row.yahtzee-row {
  gap: 8px;
}

.die {
  display: grid;
  grid-template-areas:
    "a b c"
    "d e f"
    "g h i";
  width: 60px;
  aspect-ratio: 1;
  padding: 10px;
  border: 2px solid #d6cbbc;
  border-radius: 10px;
  background: var(--dice-face);
  box-shadow: inset 0 -5px 10px rgba(0, 0, 0, 0.1), 0 10px 18px rgba(0, 0, 0, 0.28);
  animation: popIn 240ms ease-out both;
}

.die.large {
  width: 66px;
}

.die.small {
  width: 50px;
  padding: 8px;
}

.pip {
  width: 8px;
  height: 8px;
  place-self: center;
  border-radius: 50%;
  background: var(--dice-pip);
}

.pip.a { grid-area: a; }
.pip.b { grid-area: b; }
.pip.c { grid-area: c; }
.pip.d { grid-area: d; }
.pip.e { grid-area: e; }
.pip.f { grid-area: f; }
.pip.g { grid-area: g; }
.pip.h { grid-area: h; }
.pip.i { grid-area: i; }

.result-title,
.result-caption {
  margin: 0;
  color: var(--text-secondary);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.score-number {
  margin: 18px 0 2px;
  color: #ffd66f;
  text-align: center;
  font-size: 48px;
  font-weight: 950;
  line-height: 1;
}

.result-caption {
  margin-top: 4px;
  color: var(--text-primary);
  font-size: 14px;
}

.compare-hint,
.expression,
.description {
  margin: 12px 0 0;
  color: var(--text-secondary);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.badge {
  min-width: 82px;
  padding: 10px 14px;
  border-radius: var(--panel-radius);
  background: linear-gradient(145deg, var(--red-top), var(--red-bottom));
  color: var(--text-primary);
  text-align: center;
  font-size: 15px;
  font-weight: 900;
}

.detail-card,
.task-card {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--stroke-warm);
  border-radius: var(--panel-radius);
  background: var(--surface-warm);
}

.detail-card p,
.task-card p {
  margin: 0;
}

.detail-card .label,
.task-card .label {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 850;
}

.detail-card .sub,
.task-card .sub {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.task-type {
  color: #ffd66f;
  font-size: 18px;
  font-weight: 900;
}

.task-text {
  margin-top: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.55;
}

.secondary-button {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border: 1px solid #735428;
  border-radius: var(--panel-radius);
  background: #3b2b14;
  color: #fff5df;
  font-size: 14px;
  font-weight: 850;
}

.safety-notice {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #735428;
  border-radius: var(--panel-radius);
  background: rgba(59, 43, 20, 0.72);
  color: #f5dfab;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.footer-note {
  margin-top: 16px;
  text-align: center;
}

.footer-note p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 650;
}

.static-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.static-links a {
  text-decoration: none;
}

.static-links a + a::before {
  margin-right: 9px;
  content: "·";
  color: var(--text-muted);
}

.static-page .top-bar {
  margin-bottom: 24px;
}

.static-card {
  padding: 18px;
}

.static-card h2 {
  margin: 0 0 14px;
  color: #ffd66f;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.25;
}

.static-card p {
  margin: 0 0 14px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.65;
}

.static-card p:last-child {
  margin-bottom: 0;
}

.static-card a {
  color: #ffe38e;
  font-weight: 900;
  text-decoration: none;
}

@keyframes shakeCup {
  0% { transform: translateX(0) translateY(var(--cup-offset, 0px)) rotate(0deg); }
  15% { transform: translateX(-14px) translateY(calc(var(--cup-offset, 0px) + 3px)) rotate(-8deg); }
  30% { transform: translateX(14px) translateY(calc(var(--cup-offset, 0px) - 2px)) rotate(8deg); }
  45% { transform: translateX(-12px) translateY(calc(var(--cup-offset, 0px) + 2px)) rotate(-6deg); }
  60% { transform: translateX(12px) translateY(calc(var(--cup-offset, 0px) - 3px)) rotate(6deg); }
  75% { transform: translateX(-8px) translateY(calc(var(--cup-offset, 0px) + 2px)) rotate(-4deg); }
  100% { transform: translateX(0) translateY(var(--cup-offset, 0px)) rotate(0deg); }
}

@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@media (min-width: 430px) {
  .app-shell {
    padding-inline: 20px;
  }
}

@media (max-width: 374px) {
  .app-shell {
    padding-inline: 14px;
  }

  .top-bar {
    gap: 8px;
  }

  .icon-button {
    min-width: 34px;
    padding-inline: 8px;
  }

  .sound-button {
    min-width: 54px;
  }

  .die.large {
    width: 60px;
  }

  .die.small {
    width: 46px;
  }

  .score-number {
    font-size: 44px;
  }
}
