:root {
  --bg: #f5f0e6;
  --card: #fffdf8;
  --ink: #2a2520;
  --primary: #e85d04;
  --primary-dark: #c44d00;
  --accent: #5c7a29;
  --steel: #8a9199;
  --success: #2e7d4f;
  --warn: #c0392b;
  --caution: #d68910;
  --fluoro: #fff9e6;
  --shadow: rgba(42, 37, 32, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--fluoro) 0%, var(--bg) 40%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 48px,
      rgba(138, 145, 153, 0.06) 48px,
      rgba(138, 145, 153, 0.06) 49px
    );
  min-height: 100vh;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px;
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto auto auto auto 1fr auto auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 4px;
  border-bottom: 3px solid var(--steel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 1.6rem;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.hud-item {
  background: var(--card);
  border: 2px solid var(--steel);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.9rem;
}

.hud-item .label {
  color: #666;
  font-size: 0.75rem;
  margin: 0 2px;
}

.meter-val.warn {
  color: var(--warn);
  font-weight: 700;
}

.meter-val.caution {
  color: var(--caution);
  font-weight: 700;
}

.chapter-title {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
}

.narrator {
  background: #2a2520;
  color: #f5f0e6;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.55;
  min-height: 52px;
  font-style: italic;
}

.scene-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary-dark);
  padding-left: 4px;
}

.game-area {
  background: var(--card);
  border: 2px solid var(--steel);
  border-radius: 14px;
  padding: 16px;
  min-height: 220px;
  box-shadow: 0 6px 18px var(--shadow);
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.controls {
  display: flex;
  justify-content: center;
  padding-bottom: 8px;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  transition: transform 0.1s, filter 0.1s;
}

button:active {
  transform: scale(0.98);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.secondary-btn {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.ghost-btn {
  background: transparent;
  border: 2px solid var(--steel);
  color: var(--ink);
}

.choice-btn {
  background: var(--card);
  border: 2px solid var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
  flex: 1 1 140px;
  max-width: 220px;
}

.card {
  background: #fff;
  border: 2px solid #ddd;
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px var(--shadow);
}

.card.selected {
  border-color: var(--primary);
  background: #fff8f0;
  box-shadow: 0 0 0 3px rgba(232, 93, 4, 0.2);
}

.card.owned {
  opacity: 0.55;
  cursor: default;
}

.card-emoji {
  font-size: 2rem;
}

.market-grid,
.upgrade-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.card h3 {
  margin: 8px 0 4px;
  font-size: 1rem;
}

.card-cost {
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.85rem;
}

.card-desc,
.card-margin {
  font-size: 0.82rem;
  color: #555;
  margin: 4px 0;
}

.qty-picker {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed #ccc;
  text-align: center;
}

.qty-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.qty-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  min-width: 80px;
}

.minigame {
  text-align: center;
}

.minigame h3 {
  margin-top: 0;
}

.minigame-hint {
  color: #666;
  font-size: 0.9rem;
}

.rhythm-track {
  position: relative;
  height: 48px;
  background: #eee;
  border-radius: 24px;
  margin: 20px auto;
  max-width: 320px;
  overflow: hidden;
}

.rhythm-zone {
  position: absolute;
  left: 38%;
  width: 24%;
  height: 100%;
  background: rgba(46, 125, 79, 0.35);
  border-left: 2px solid var(--success);
  border-right: 2px solid var(--success);
}

.rhythm-indicator {
  position: absolute;
  top: 8px;
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.label-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin: 24px 0;
}

.tray-zone {
  width: 160px;
  height: 100px;
  border: 3px dashed var(--steel);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  background: #fafafa;
}

.label-tag {
  background: #ff6b35;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 800;
  cursor: grab;
  user-select: none;
  box-shadow: 0 3px 0 #c44d00;
}

.rush-board {
  display: grid;
  gap: 12px;
}

.rush-timer {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.rush-stats {
  color: #666;
  font-size: 0.9rem;
}

.customer-area {
  min-height: 100px;
  display: grid;
  place-items: center;
  background: var(--fluoro);
  border-radius: 10px;
  padding: 16px;
}

.student-bubble,
.npc-encounter {
  text-align: center;
}

.student-bubble span {
  font-size: 2rem;
}

.npc-emoji {
  font-size: 2.2rem;
  display: block;
}

.empty-queue,
.wait-hint {
  color: #888;
  font-style: italic;
}

.summary-card {
  display: grid;
  gap: 10px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.summary-row strong.positive {
  color: var(--success);
}

.summary-row strong.warn {
  color: var(--warn);
}

.year-end {
  text-align: center;
  line-height: 1.8;
}

.chapter-label {
  font-weight: 800;
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.ending-emoji {
  font-size: 4rem;
  text-align: center;
  padding: 24px;
}

dialog {
  border: none;
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog h2 {
  margin-top: 0;
}

.reflection {
  font-style: italic;
  color: #555;
  border-left: 3px solid var(--primary);
  padding-left: 12px;
}

.ending-stats {
  font-size: 0.85rem;
  color: #666;
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .choices {
    flex-direction: column;
  }

  .choice-btn {
    max-width: none;
  }
}
