:root {
  --ink: #14221f;
  --muted: #4a635c;
  --paper: #f3f0e8;
  --panel: rgba(255, 252, 246, 0.82);
  --accent: #d9772f;
  --accent-deep: #b85a18;
  --bar: #2f6b5a;
  --bar-hot: #d9772f;
  --die: #fffaf2;
  --die-edge: #d8cfc0;
  --shadow: 0 18px 40px rgba(20, 34, 31, 0.14);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #1a2f2a;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 55% at 15% 10%, rgba(217, 119, 47, 0.28), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 20%, rgba(84, 150, 128, 0.35), transparent 50%),
    linear-gradient(165deg, #1a2f2a 0%, #243f38 42%, #1e3530 100%);
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.app {
  width: min(100% - 2rem, 520px);
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) 0 max(2.5rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 100dvh;
  justify-content: center;
}

.brand {
  text-align: center;
  color: var(--paper);
  animation: rise 0.7s ease both;
}

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.05;
}

.brand-desc {
  margin: 0.45rem 0 0;
  font-size: 0.98rem;
  color: rgba(243, 240, 232, 0.72);
}

.stage {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.5rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
  animation: rise 0.7s ease 0.08s both;
}

.dice-row {
  display: flex;
  justify-content: center;
  gap: clamp(0.7rem, 4vw, 1.1rem);
}

.die {
  width: clamp(64px, 18vw, 78px);
  height: clamp(64px, 18vw, 78px);
  border-radius: 14px;
  background:
    linear-gradient(145deg, #ffffff 0%, var(--die) 55%, #f0e6d6 100%);
  border: 1px solid var(--die-edge);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 10px 18px rgba(20, 34, 31, 0.16);
  display: grid;
  place-items: center;
  transition: transform 0.25s ease;
}

.die span {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6vw, 2.2rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.die.rolling {
  animation: shake 0.45s ease;
}

.sum-line {
  margin: 1.15rem 0 0;
  text-align: center;
  font-size: 0.95rem;
  color: var(--muted);
}

.sum-line strong {
  display: inline-block;
  margin-left: 0.35rem;
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--accent-deep);
  min-width: 2ch;
  vertical-align: -0.15em;
  transition: transform 0.2s ease;
}

.sum-line strong.pop {
  animation: pop 0.35s ease;
}

.actions {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 0.7rem;
  animation: rise 0.7s ease 0.14s both;
}

button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: scale(0.97);
}

.btn-roll {
  background: linear-gradient(180deg, #e89245 0%, var(--accent) 100%);
  color: #fffaf2;
  box-shadow: 0 10px 22px rgba(217, 119, 47, 0.35);
}

.btn-roll:hover {
  background: linear-gradient(180deg, #f0a05a 0%, #e07f36 100%);
}

.btn-ghost {
  background: rgba(255, 252, 246, 0.14);
  color: var(--paper);
  border: 1px solid rgba(255, 252, 246, 0.22);
}

.btn-ghost:hover {
  background: rgba(255, 252, 246, 0.22);
}

.chart-section {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.15rem 1rem 1rem;
  box-shadow: var(--shadow);
  animation: rise 0.7s ease 0.2s both;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  padding: 0 0.2rem;
}

.chart-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}

.chart-head p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.chart {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  align-items: end;
  gap: clamp(2px, 1vw, 5px);
  height: 160px;
  padding: 0.2rem 0 0;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 0.3rem;
  min-width: 0;
}

.bar {
  width: 100%;
  max-width: 22px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, #4a9a82 0%, var(--bar) 100%);
  min-height: 2px;
  height: 2px;
  transition: height 0.35s cubic-bezier(0.22, 1, 0.36, 1), background 0.25s ease;
}

.bar.hot {
  background: linear-gradient(180deg, #f0a05a 0%, var(--bar-hot) 100%);
}

.bar-label {
  font-size: 0.62rem;
  color: var(--muted);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.bar-count {
  font-size: 0.58rem;
  color: var(--ink);
  opacity: 0.55;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-height: 0.7em;
}

@media (min-width: 480px) {
  .chart {
    height: 190px;
  }

  .bar-label {
    font-size: 0.72rem;
  }

  .bar-count {
    font-size: 0.66rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateY(0) rotate(0);
  }
  25% {
    transform: translateY(-8px) rotate(-8deg);
  }
  50% {
    transform: translateY(2px) rotate(6deg);
  }
  75% {
    transform: translateY(-4px) rotate(-3deg);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}
