:root {
  color-scheme: light;
  --coral: #E9654F;
  --coral-bright: #FF7352;
  --ink: #2A211A;
  --cream: #FFF7EF;
  --peach: #FFE2D6;
  --caramel: #D9B88F;
  --blue: #E7F4F5;
  --white: #FFFFFF;
  --muted: #715F53;
}

* {
  box-sizing: border-box;
}

html,
body {
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--cream);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

.quiz-shell,
.poster-dialog {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

button {
  font: inherit;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid rgba(233, 101, 79, 0.28);
  outline-offset: 3px;
}

.quiz-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.quiz-shell.home-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100svh;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow,
.result-kicker {
  width: max-content;
  margin: 0 0 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--coral);
  color: var(--white);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.25;
  font-weight: 800;
}

.title-accent::before {
  content: " ";
}

.home-active .title-main,
.home-active .title-accent {
  display: block;
}

.home-active .title-accent::before {
  content: "";
}

.home-active .quiz-header h1 {
  font-size: 50px;
  line-height: 1.08;
}

.home-active .title-accent {
  margin-top: 3px;
  color: var(--coral);
  font-size: 54px;
}

.icon-button {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  font-size: 27px;
  font-weight: 700;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--peach);
}

.intro-view {
  min-height: 0;
  text-align: center;
}

.home-active .quiz-header {
  margin-bottom: 0;
  padding-bottom: 10px;
}

.home-active .intro-view {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.topic-carousel {
  align-self: stretch;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  width: min(100%, 420px);
  min-height: 0;
  margin: 0 auto;
  gap: 8px;
}

.topic-frame {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  width: 100%;
  max-width: 423px;
  height: auto;
  aspect-ratio: 8 / 9;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--white);
  box-shadow: 0 7px 0 rgba(42, 33, 26, 0.12);
}

.topic-slide {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--white);
  object-fit: contain;
}

.topic-nav {
  grid-row: 1;
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.topic-nav:hover {
  background: var(--peach);
}

#topic-prev {
  grid-column: 1;
}

#topic-next {
  grid-column: 3;
}

.topic-count {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.intro-actions {
  align-self: end;
  padding-top: 12px;
}

.intro-prompt {
  margin: 0 auto 18px;
  color: var(--muted);
  font-size: 19px;
  line-height: 1.6;
  font-weight: 700;
}

.start-button {
  min-width: 170px;
  min-height: 54px;
  padding: 12px 24px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--coral);
  color: var(--white);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

.start-button:hover {
  background: var(--coral-bright);
}

.start-button span {
  display: inline-block;
  margin-left: 6px;
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  position: absolute;
  right: 0;
  bottom: -34px;
  z-index: 10;
  padding: 5px 8px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--white);
  content: attr(data-tooltip);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.quiz-panel,
.result-panel {
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--white);
}

.quiz-panel {
  padding: 32px;
}

.progress-row {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--peach);
}

.progress-track span {
  display: block;
  width: 16.666%;
  height: 100%;
  background: var(--coral-bright);
  transition: width 180ms ease;
}

.quiz-panel h2 {
  max-width: 680px;
  margin: 36px 0 26px;
  font-size: 27px;
  line-height: 1.35;
  font-weight: 800;
}

.quiz-panel h2::after {
  display: block;
  width: 88px;
  height: 7px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--coral-bright);
  content: "";
  transform: rotate(-2deg);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.choice-button {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  min-height: 92px;
  padding: 16px 18px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.choice-button:nth-child(2n) {
  background: var(--blue);
}

.choice-button:hover {
  background: var(--peach);
  transform: translateY(-2px);
}

.choice-button:active {
  transform: translateY(0);
}

.choice-icon {
  font-size: 32px;
  line-height: 1;
  text-align: center;
}

.choice-label {
  min-width: 0;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 700;
}

.result-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 430px);
  gap: 36px;
  align-items: center;
  padding: 34px;
}

.result-copy h2 {
  margin: 14px 0 12px;
  font-size: 34px;
  line-height: 1.3;
  font-weight: 800;
}

.result-word {
  display: block;
  margin-top: 5px;
  color: var(--coral);
  font-size: 30px;
  overflow-wrap: anywhere;
}

.result-reason {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.8;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.restart-button,
.poster-button,
.poster-save-button {
  min-height: 48px;
  padding: 10px 22px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.restart-button,
.poster-save-button {
  background: var(--coral);
  color: var(--white);
}

.poster-button {
  background: var(--blue);
  color: var(--ink);
}

.restart-button:hover,
.poster-save-button:hover {
  background: var(--coral-bright);
}

.poster-button:hover {
  background: var(--peach);
}

.poster-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.result-card-frame {
  margin: 0;
}

.result-card-frame img {
  display: block;
  width: 100%;
  max-height: 68vh;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--white);
  object-fit: contain;
}

.result-card-frame figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.poster-dialog {
  width: min(92vw, 540px);
  max-height: min(92svh, 820px);
  padding: 18px;
  overflow: auto;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 12px 0 rgba(42, 33, 26, 0.16);
}

.poster-dialog::backdrop {
  background: rgba(42, 33, 26, 0.56);
}

.poster-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.poster-dialog-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
}

.poster-close-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.poster-close-button:hover {
  background: var(--peach);
}

.poster-preview-frame {
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--white);
}

.poster-preview-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.poster-dialog-actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.poster-save-button {
  min-width: 160px;
}

.poster-save-button span {
  margin-right: 5px;
  font-size: 20px;
}

.poster-status {
  margin: 12px 0 0;
  color: #9C2F20;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.error-message {
  margin: 24px 0 0;
  color: #9C2F20;
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .quiz-shell {
    width: min(100% - 20px, 620px);
    padding: 20px 0 32px;
  }

  .quiz-shell.home-active {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .quiz-header {
    align-items: flex-start;
    gap: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .home-active .quiz-header h1 {
    font-size: 38px;
    line-height: 1.08;
  }

  .home-active .title-accent {
    margin-top: 2px;
    font-size: 42px;
  }

  .topic-carousel {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    width: 100%;
    gap: 4px;
  }

  .topic-frame {
    box-shadow: 0 4px 0 rgba(42, 33, 26, 0.12);
  }

  .topic-nav {
    width: 36px;
    height: 36px;
    font-size: 21px;
  }

  .topic-count {
    margin-top: 2px;
  }

  .intro-actions {
    padding-top: 8px;
  }

  .intro-prompt {
    width: min(100%, 330px);
    margin-bottom: 14px;
    font-size: 16px;
  }

  .quiz-panel {
    padding: 22px 16px;
  }

  .progress-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .quiz-panel h2 {
    margin-top: 28px;
    font-size: 23px;
  }

  .choice-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .choice-button {
    min-height: 74px;
    grid-template-columns: 46px minmax(0, 1fr);
    padding: 12px 14px;
  }

  .choice-icon {
    font-size: 28px;
  }

  .choice-label {
    font-size: 17px;
  }

  .result-panel {
    grid-template-columns: 1fr;
    gap: 26px;
    padding: 24px 16px;
  }

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

  .result-actions button {
    width: 100%;
    padding-inline: 12px;
  }

  .result-copy h2 {
    font-size: 29px;
  }

  .result-word {
    font-size: 26px;
  }

  .result-card-frame img {
    max-height: none;
  }

  .poster-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
