:root {
  --bg: #fff8ec;
  --ink: #3b3226;
  --accent: #ffb54c;
  --accent-dark: #e8912a;
  --card: #ffffff;
  --line: #eadfcb;
  --good: #ff5a6e;
  --bad: #4a7bd8;
  --shadow: 0 4px 0 rgba(59, 50, 38, 0.15);
  --radius: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

svg {
  display: block;
}

#app {
  height: 100dvh;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.hidden {
  display: none !important;
}

/* ---- ヘッダ ---- */
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.bar h1 {
  margin: 0;
  font-size: clamp(22px, 5vw, 32px);
}

.icon-btn {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}

.icon-btn svg,
.tool svg,
.big-btn svg,
.next svg {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- ホーム ---- */
.home .title {
  text-align: center;
  font-size: clamp(32px, 9vw, 56px);
  margin: 24px 0;
  color: var(--accent-dark);
}

.topics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.topic-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 26px;
  font-weight: 700;
  transition: transform 0.1s;
}

.topic-card:active,
.level-start:active,
.choice:active {
  transform: translateY(3px);
}

.topic-icon {
  width: 110px;
  height: 110px;
}

/* ---- レベル ---- */
.level-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.level-card {
  display: flex;
  gap: 12px;
}

.level-start {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 30px;
  font-weight: 700;
  transition: transform 0.1s;
}

.level-icons {
  display: flex;
  gap: 2px;
  min-width: 96px;
  justify-content: center;
}

.doll-icon {
  width: 46px;
  height: 60px;
}

.level-label {
  flex: 1;
  text-align: left;
}

.best {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 22px;
}

.best svg {
  width: 26px;
  height: 26px;
  fill: #ffc93c;
}

.level-demo {
  flex: none;
  width: 84px;
  border-radius: var(--radius);
  background: #e9f4ff;
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 700;
}

/* ---- もんだい ---- */
.quiz {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  position: relative;
}

.progress {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--line);
}

.dot.done {
  background: var(--accent);
}

.dot.now {
  background: var(--card);
  box-shadow: 0 0 0 3px var(--accent);
}

.demo-badge {
  padding: 6px 16px;
  border-radius: 999px;
  background: #e9f4ff;
  font-weight: 700;
  font-size: 20px;
}

.quiz .bar::after {
  content: '';
  width: 52px;
  flex: none;
}

.quiz.is-demo .bar::after {
  display: none;
}

.stage-wrap {
  position: relative;
  min-height: 0;
}

.stage {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 0;
}

.three-view {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.three-view canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.stage-tools {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}

.tool {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}

.tool.eye {
  background: var(--accent);
  color: #fff;
}

.choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.choice {
  position: relative;
  aspect-ratio: 1;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12%;
  transition: transform 0.1s, opacity 0.2s;
}

.shape {
  width: 100%;
  height: 100%;
}

.shape rect {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 0.08;
}

/* ◯ と ✕ */
.choice.right::after,
.choice.wrong::after {
  content: '';
  position: absolute;
  inset: 4%;
  animation: pop 0.35s ease-out;
  pointer-events: none;
}

.choice.right::after {
  border: 9px solid var(--good);
  border-radius: 50%;
}

.choice.wrong {
  opacity: 0.55;
}

.choice.wrong::after {
  background:
    linear-gradient(45deg, transparent 45%, var(--bad) 45%, var(--bad) 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--bad) 45%, var(--bad) 55%, transparent 55%);
}

.quiz.solved .choice:not(.right) {
  opacity: 0.35;
}

@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.next {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 0 var(--accent-dark);
  display: grid;
  place-items: center;
  z-index: 5;
  animation: pop 0.3s ease-out, bounce 1.2s 0.4s ease-in-out infinite;
}

.next svg {
  stroke: none;
  margin-left: 6px;
}

@keyframes bounce {
  50% {
    transform: translateY(-6px);
  }
}

/* 縦長: 絵が上、選択肢 2x2 が下 */
@media (orientation: portrait) {
  .choices {
    grid-template-columns: repeat(2, 1fr);
    max-width: min(100%, 44dvh);
    margin: 0 auto;
    width: 100%;
  }
}

/* 横長: 絵が左、選択肢 2x2 が右 */
@media (orientation: landscape) {
  .quiz {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .quiz .bar {
    grid-column: 1 / -1;
  }
  .choices {
    grid-template-columns: repeat(2, 1fr);
    align-content: center;
    width: min(46vw, calc(100dvh - 110px));
  }
}

/* ---- けっか ---- */
.result {
  position: absolute;
  inset: 0;
  background: rgba(255, 248, 236, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  z-index: 10;
}

.stars {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.star svg {
  width: clamp(48px, 14vw, 90px);
  height: clamp(48px, 14vw, 90px);
  fill: var(--line);
}

.star.on svg {
  fill: #ffc93c;
  stroke: #e8a21a;
  stroke-width: 0.8;
}

.star {
  animation: pop 0.4s ease-out backwards;
}

.result-buttons {
  display: flex;
  gap: 28px;
}

.big-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}

.big-btn.retry {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 0 var(--accent-dark);
}
