:root {
  --ink: #2c2a33;
  --muted: #676170;
  --paper: #fffaf0;
  --surface: #ffffff;
  --mint: #d9f8e8;
  --sky: #d9f0ff;
  --yellow: #ffe68a;
  --pink: #ffdce8;
  --orange: #ffb15f;
  --green: #40b870;
  --blue: #3387d9;
  --red: #e65858;
  --shadow: 0 14px 34px rgba(44, 42, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background:
    linear-gradient(135deg, rgba(255, 230, 138, 0.7), rgba(217, 240, 255, 0.88)),
    var(--paper);
}

.result-effect {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}

.result-effect::before {
  display: grid;
  place-items: center;
  width: min(54vw, 310px);
  aspect-ratio: 1;
  border-radius: 50%;
  color: #fff;
  font-size: clamp(7rem, 22vw, 12rem);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 8px 18px rgba(44, 42, 51, 0.22);
  box-shadow: 0 24px 70px rgba(44, 42, 51, 0.22);
}

.result-effect.correct {
  animation: effectFade 900ms ease-out;
}

.result-effect.correct::before {
  content: "○";
  background:
    radial-gradient(circle at 28% 25%, rgba(255, 255, 255, 0.9), transparent 24%),
    var(--green);
  animation: popCorrect 900ms ease-out;
}

.result-effect.wrong {
  animation: effectFade 760ms ease-out;
}

.result-effect.wrong::before {
  content: "×";
  background: var(--red);
  animation: shakeWrong 760ms ease-out;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.hero,
.control-band,
.question-band,
.workspace {
  display: grid;
  gap: 18px;
}

.hero {
  grid-template-columns: 1fr;
  align-items: center;
  min-height: 180px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #875400;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.5rem, 7vw, 5.5rem);
  line-height: 1;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.45rem;
}

.lead {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1.7;
}

.wallet-card {
  display: grid;
  place-items: center;
  min-width: 170px;
  min-height: 92px;
  padding: 12px 18px;
  border: 4px solid #2c2a33;
  border-radius: 8px;
  background: var(--yellow);
  box-shadow: var(--shadow);
}

.wallet-card span {
  font-weight: 700;
}

.wallet-card strong {
  font-size: 2rem;
}

.control-band,
.question-band,
.shop-area,
.cart-area {
  border: 3px solid rgba(44, 42, 51, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
}

.control-band {
  grid-template-columns: 1.45fr 1.05fr auto auto;
  align-items: end;
  padding: 18px;
}

.control-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
}

.segmented button,
.reset-button,
.clear-button,
.answer-row button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
}

.segmented button {
  padding: 8px 14px;
  background: var(--sky);
}

.segmented button.active {
  color: #fff;
  background: var(--blue);
}

.reset-button {
  padding: 8px 18px;
  background: var(--orange);
}

.question-band {
  grid-template-columns: 1fr;
  align-items: center;
  padding: 22px;
}

.question-copy {
  margin-bottom: 14px;
  padding-left: 14px;
  border-left: 6px solid var(--green);
}

.mode-title {
  margin-bottom: 8px;
  color: #0f6f3f;
  font-size: 1.6rem;
  font-weight: 900;
}

.question-text {
  margin-bottom: 0;
  font-size: 1.3rem;
  line-height: 1.6;
}

.answer-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

.answer-row,
.choice-row {
  display: grid;
  align-items: center;
  gap: 10px;
}

.answer-row {
  grid-template-columns: 1fr auto auto;
}

.choice-row {
  grid-template-columns: 1fr 1fr;
}

.choice-row.is-hidden,
.answer-row.is-hidden {
  display: none;
}

.answer-row input {
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  border: 3px solid #c8d1dc;
  border-radius: 8px;
  background: #fff;
  font-size: 1.35rem;
  font-weight: 800;
}

.answer-row button,
.choice-row button {
  padding: 8px 18px;
  color: #fff;
  background: var(--green);
}

.choice-row button:last-child {
  background: var(--red);
}

.choice-row button.effect-correct {
  animation: buttonPop 520ms ease-out;
}

.choice-row button.effect-wrong {
  animation: buttonShake 420ms ease-out;
}

.feedback {
  min-height: 32px;
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.feedback.correct {
  color: #11804a;
}

.feedback.wrong {
  color: var(--red);
}

.workspace {
  grid-template-columns: 1fr 330px;
  align-items: start;
}

.shop-area,
.cart-area {
  padding: 18px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

.product-card {
  display: grid;
  gap: 8px;
  min-height: 154px;
  padding: 14px;
  border: 3px solid rgba(44, 42, 51, 0.14);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  box-shadow: 0 8px 18px rgba(44, 42, 51, 0.08);
}

.product-card:hover {
  transform: translateY(-2px);
}

.product-card.is-selected {
  border-color: var(--blue);
  background: #fff8d7;
  box-shadow:
    0 0 0 5px rgba(255, 230, 138, 0.95),
    0 16px 30px rgba(51, 135, 217, 0.22);
  transform: translateY(-2px);
}

.product-icon {
  font-size: 3rem;
  line-height: 1;
}

.product-name {
  font-weight: 900;
}

.product-price {
  color: #8b4b00;
  font-size: 1.25rem;
  font-weight: 900;
}

.cart-list {
  display: grid;
  gap: 8px;
  min-height: 180px;
  margin-bottom: 16px;
}

.cart-item,
.empty-cart {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--mint);
  font-weight: 800;
}

.empty-cart {
  justify-content: center;
  color: var(--muted);
  background: #f4f3f1;
}

.learning-hint {
  margin-bottom: 14px;
  padding: 14px;
  border: 3px dashed rgba(64, 184, 112, 0.36);
  border-radius: 8px;
  color: #167044;
  background: #effbf4;
  font-weight: 900;
  line-height: 1.5;
  text-align: center;
}

.summary {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.summary div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--pink);
}

.summary span {
  font-weight: 800;
}

.summary strong {
  font-size: 1.55rem;
}

.clear-button {
  width: 100%;
  background: #e7ecf2;
}

@media (max-width: 860px) {
  .hero,
  .control-band,
  .question-band,
  .workspace {
    grid-template-columns: 1fr;
  }

  .wallet-card {
    min-width: 0;
  }

  .segmented {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  h1 {
    font-size: 2.5rem;
  }

  .question-band,
  .control-band,
  .shop-area,
  .cart-area {
    padding: 14px;
  }

  .answer-row {
    grid-template-columns: 1fr auto;
  }

  .answer-row button {
    grid-column: 1 / -1;
  }
}

.ipad-page {
  min-height: 100svh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ipad-shell {
  width: min(100% - 36px, 1240px);
  padding: max(18px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.ipad-page button,
.ipad-page input {
  min-height: 58px;
}

.ipad-page .hero {
  min-height: 150px;
}

.ipad-page h1 {
  font-size: clamp(3rem, 7vw, 5.2rem);
}

.ipad-page .lead,
.ipad-page .question-text {
  font-size: 1.28rem;
}

.ipad-page .control-band,
.ipad-page .question-band,
.ipad-page .shop-area,
.ipad-page .cart-area {
  border-width: 4px;
}

.ipad-page .segmented {
  gap: 10px;
}

.ipad-page .segmented button,
.ipad-page .reset-button,
.ipad-page .clear-button,
.ipad-page .answer-row button,
.ipad-page .choice-row button {
  font-size: 1.08rem;
}

.ipad-page .product-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.ipad-page .product-card {
  min-height: 178px;
  padding: 18px;
}

.ipad-page .product-icon {
  font-size: 3.45rem;
}

.ipad-page .cart-area {
  position: sticky;
  top: max(16px, env(safe-area-inset-top));
}

@media (orientation: portrait) and (min-width: 700px) {
  .ipad-page .hero,
  .ipad-page .control-band,
  .ipad-page .question-band,
  .ipad-page .workspace {
    grid-template-columns: 1fr;
  }

  .ipad-page .wallet-card {
    min-width: 0;
  }

  .ipad-page .workspace {
    gap: 18px;
  }

  .ipad-page .cart-area {
    position: static;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  .ipad-page .workspace {
    grid-template-columns: 1fr 360px;
  }
}

@keyframes effectFade {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes popCorrect {
  0% {
    transform: scale(0.35) rotate(-14deg);
  }
  42% {
    transform: scale(1.08) rotate(5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes shakeWrong {
  0% {
    transform: scale(0.55) rotate(0deg);
  }
  20% {
    transform: scale(1.04) rotate(-7deg);
  }
  38% {
    transform: scale(1.02) rotate(7deg);
  }
  56% {
    transform: scale(1) rotate(-4deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes buttonPop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.09);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes buttonShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  50% {
    transform: translateX(7px);
  }
  75% {
    transform: translateX(-4px);
  }
}

/* LiNest v3: 教材の色と操作サイズを保った外観調整 */
body.linest-themed {
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --paper: var(--linest-bg);
  --surface: var(--linest-surface);
  --mint: var(--linest-green-soft);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-shell,
body.linest-themed .hero > *,
body.linest-themed .control-band > *,
body.linest-themed .workspace > * {
  min-width: 0;
}

body.linest-themed .hero {
  min-height: 0;
  padding: 22px 24px;
  border: 1px solid var(--linest-border);
  border-left: 6px solid var(--linest-green-bright);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .control-band,
body.linest-themed .question-band,
body.linest-themed .shop-area,
body.linest-themed .cart-area {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .wallet-card {
  border-color: var(--linest-heading);
  background: #fff8df;
  box-shadow: var(--linest-shadow);
}

body.linest-themed .segmented button {
  background: var(--linest-green-soft);
}

body.linest-themed .segmented button.active {
  color: #fff;
  background: var(--linest-green);
}

body.linest-themed .reset-button {
  color: #fff;
  background: var(--linest-terracotta);
}

body.linest-themed .clear-button {
  border: 1px solid var(--linest-terracotta);
  color: var(--linest-terracotta-dark);
  background: #fffaf6;
}

body.linest-themed .question-copy {
  border-left-color: var(--linest-green-bright);
}

body.linest-themed .mode-title {
  color: var(--linest-green-dark);
}

body.linest-themed .product-card {
  border-color: var(--linest-border);
  box-shadow: 0 6px 16px rgba(74, 55, 40, 0.07);
}

body.linest-themed .product-card.is-selected {
  border-color: var(--linest-green);
  background: var(--linest-green-soft);
  box-shadow:
    0 0 0 4px rgba(47, 158, 68, 0.16),
    0 12px 24px rgba(74, 55, 40, 0.1);
}

body.linest-themed :where(.segmented button, .reset-button, .clear-button, .choice-row button) {
  min-width: 0;
  line-height: 1.35;
  white-space: normal;
}

@media (max-width: 1100px) and (min-width: 861px) {
  body.linest-themed .control-band {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  body.linest-themed .wallet-card {
    min-width: 0;
  }

  body.linest-themed .reset-button {
    align-self: stretch;
    min-height: 92px;
  }
}

@media (max-width: 520px) {
  body.linest-themed .hero {
    padding: 18px 16px;
  }

  body.linest-themed .segmented button {
    padding-inline: 8px;
    font-size: 0.95rem;
  }
}
