:root {
  color-scheme: light;
  --bg: #fbf7ef;
  --ink: #1f2024;
  --soft-ink: #393631;
  --muted: #746b5f;
  --paper: #fffdf8;
  --paper-2: #fff5df;
  --line: rgba(31, 32, 36, 0.12);
  --line-strong: rgba(31, 32, 36, 0.2);
  --accent: #ff6048;
  --accent-2: #147d72;
  --shadow: 0 18px 48px rgba(49, 38, 25, 0.13);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(140deg, rgba(255, 96, 72, 0.12), transparent 35%),
    linear-gradient(320deg, rgba(20, 125, 114, 0.11), transparent 32%),
    var(--bg);
  color: var(--ink);
  font-family: "Inter", "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 16px auto 28px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 24px;
  align-items: end;
  padding: 24px 4px 18px;
  overflow: hidden;
}

.topbar > *,
.workspace > * {
  min-width: 0;
}

.brand {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(2.1rem, 4.2vw, 4.9rem);
  line-height: 1.02;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h1 span {
  display: block;
}

.tagline {
  max-width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 18px;
  align-items: start;
}

.experience,
.control-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.experience {
  display: grid;
  gap: 18px;
  min-height: 720px;
  padding: clamp(16px, 2.2vw, 28px);
}

.control-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.mode-tabs {
  display: flex;
  width: fit-content;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.mode-btn {
  min-width: 86px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.mode-btn.active {
  background: var(--ink);
  color: #fff;
}

.scene {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 100%;
  overflow: hidden;
}

.wheel-scene {
  align-content: center;
}

.wheel-wrap {
  position: relative;
  width: min(100%, 56vh, 570px);
  aspect-ratio: 1;
}

#wheelCanvas {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 22px 44px rgba(49, 38, 25, 0.18));
}

.pointer {
  position: absolute;
  z-index: 3;
  top: -2px;
  left: 50%;
  width: 34px;
  height: 46px;
  transform: translateX(-50%);
  background: var(--ink);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.wheel-hub {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 92px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 8px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(31, 32, 36, 0.22);
  pointer-events: none;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.primary-action,
.secondary-action,
.line-btn,
.small-btn {
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 900;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.primary-action {
  min-width: 160px;
  padding: 0 22px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(255, 96, 72, 0.26);
}

.secondary-action,
.line-btn {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.primary-action,
.secondary-action {
  min-width: 0;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: progress;
  opacity: 0.65;
}

.box-scene {
  align-content: center;
  min-height: 470px;
}

.box-copy {
  max-width: 680px;
  text-align: center;
}

.box-copy h2 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 3vw, 3rem);
}

.box-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 12px;
  width: min(760px, 100%);
}

.mystery-card {
  position: relative;
  min-height: 136px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  overflow: hidden;
  text-align: left;
}

.mystery-card::before {
  content: "?";
  position: absolute;
  right: 14px;
  bottom: -10px;
  color: rgba(31, 32, 36, 0.08);
  font-size: 5rem;
  font-weight: 900;
}

.mystery-card span {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.mystery-card strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 34px;
  font-size: 1.15rem;
}

.mystery-card.is-hidden strong {
  color: transparent;
  text-shadow: 0 0 10px rgba(31, 32, 36, 0.18);
}

.mystery-card.is-active {
  border-color: var(--accent);
  background: #ffe0d8;
  box-shadow: 0 16px 30px rgba(255, 96, 72, 0.22);
}

.mystery-card.is-winner {
  background: var(--accent);
  color: #fff;
}

.mystery-card.is-winner span {
  color: rgba(255, 255, 255, 0.82);
}

.option-preview,
.result-panel,
.panel-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

.option-preview {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.section-head strong {
  color: var(--soft-ink);
  font-size: 0.9rem;
}

.preview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-chip {
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--soft-ink);
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.result-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 14px;
  align-items: center;
  padding: 18px;
}

.result-panel span {
  grid-row: span 2;
  align-self: center;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 900;
}

.result-panel strong {
  font-size: clamp(1.55rem, 3vw, 2.7rem);
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.result-panel p {
  margin: 0;
  color: var(--muted);
}

.result-panel.empty strong {
  color: var(--muted);
}

.result-panel.flash {
  animation: resultFlash 520ms ease;
}

@keyframes resultFlash {
  0% {
    transform: translateY(8px);
    background: #ffe0d8;
  }
  100% {
    transform: translateY(0);
  }
}

.control-panel {
  position: sticky;
  top: 14px;
}

.panel-section {
  padding: 14px;
}

.title-input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 800;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.template-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.template-btn {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 900;
}

.item-list {
  display: grid;
  gap: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px 38px;
  gap: 8px;
  align-items: center;
}

.item-row input {
  min-width: 0;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

.item-row input[type="number"] {
  text-align: center;
}

.delete-btn {
  min-height: 42px;
  border-radius: var(--radius);
  background: rgba(255, 96, 72, 0.13);
  color: #d33a28;
  font-size: 1.18rem;
  font-weight: 900;
}

.small-btn {
  min-height: 34px;
  padding: 0 12px;
  background: var(--ink);
  color: #fff;
  font-size: 0.86rem;
}

.small-btn.quiet {
  background: rgba(31, 32, 36, 0.08);
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
}

.history-list li {
  padding-left: 4px;
  overflow-wrap: anywhere;
}

.actions-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.line-btn.danger {
  color: #d33a28;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

button:hover {
  border-color: var(--line-strong);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 96, 72, 0.34);
  outline-offset: 2px;
}

@media (max-width: 1080px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(360px, calc(100vw - 20px));
    max-width: 1480px;
    margin-top: 10px;
  }

  .topbar {
    padding-top: 12px;
    gap: 12px;
  }

  h1 {
    max-width: 100%;
    font-size: clamp(1.9rem, 8.6vw, 2.6rem);
    line-height: 1.06;
    word-break: break-all;
  }

  .tagline {
    font-size: 0.95rem;
    word-break: break-all;
  }

  .experience,
  .control-panel {
    padding: 12px;
  }

  .mode-tabs,
  .stage-actions {
    width: 100%;
  }

  .mode-btn,
  .primary-action,
  .secondary-action {
    flex: 1;
  }

  .stage-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .wheel-wrap {
    width: min(100%, 330px);
  }

  .wheel-hub {
    width: 76px;
    border-width: 6px;
  }

  .template-list {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: minmax(0, 1fr) 56px 38px;
  }

  .preview-chips {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .preview-chip {
    display: grid;
    place-items: center;
    min-height: 38px;
    padding: 7px 4px;
    text-align: center;
    line-height: 1.15;
  }

  .result-panel {
    grid-template-columns: 1fr;
  }

  .result-panel span {
    grid-row: auto;
    width: fit-content;
  }
}
