/*
  おかいもの ゲーム だけの みため
  （いろなどの きほんは ../common/common.css に ある）
*/

:root {
  --color-miss: #ef3b55;        /* まちがい（あか） */
  --color-change: #6a5cff;      /* 「おつり すくなく」の いろ */
  --color-tidy: #1fa38a;        /* 「おさいふ すっきり」の いろ */
  --color-leather: #a8764a;     /* おさいふの いろ */
  --color-leather-dark: #7d5230;
}

/* ===== がめん1: せってい ===== */
.setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 20px 32px;
}

.rule-text {
  width: 100%;
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius-medium);
  background: #f1effb;
  font-size: 1.05rem;
  text-align: center;
  word-break: keep-all; /* ことばの とちゅうで おりかえさない */
}

.setting {
  width: 100%;
}

.setting-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  text-align: center;
}

.setting-note {
  min-height: 3em;
  margin: 8px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text-sub);
  text-align: center;
  word-break: keep-all;
}

/* えらぶ ボタン（むずかしさ・もんだい） */
.choice-list {
  display: grid;
  gap: 8px;
  max-width: 420px;
  margin: 0 auto;
}

.choice-list--level {
  grid-template-columns: repeat(3, 1fr);
}

.choice-list--mode {
  grid-template-columns: repeat(2, 1fr);
}

/* スマホ だけで つかう かいぎょう */
.sp-break {
  display: none;
}

.choice {
  display: block;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ほんものの ラジオボタンは みえなく する（キーボードでは つかえる） */
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 6px 2px;
  border: 3px solid var(--color-line);
  border-radius: var(--radius-medium);
  background: #faf9ff;
  font-size: 1rem;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.choice:hover .choice-inner {
  border-color: #c9c5ee;
}

.choice input:checked + .choice-inner {
  border-color: var(--color-main);
  background: var(--color-main);
  color: #fff;
}

.choice input:focus-visible + .choice-inner {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.setup-best {
  margin: 0;
  padding: 8px 18px;
  border-radius: 999px;
  background: #f1effb;
  font-size: 0.95rem;
  color: var(--color-text-sub);
  text-align: center;
}

.setup-best span {
  color: var(--color-text);
}

/* ===== がめん2: あそぶ ===== */
.play {
  --s: 1; /* おかねの おおきさ（main.js で がめんの たかさに あわせて かえる） */
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

/* もんだい・せいかい・じかん */
.hud {
  display: flex;
  gap: 8px;
}

.hud-item {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 4px 4px 6px;
  border-radius: var(--radius-medium);
  background: rgba(255, 255, 255, 0.1);
}

.hud-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
}

.hud-value {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.play-best {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
  text-align: center;
}

.play-best span {
  color: var(--color-yellow);
}

/* かう もの と ねだん */
.order {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-medium);
}

.order-item {
  flex: none;
  width: 80px;
  height: 80px;
  padding: 4px;
  border: 3px solid var(--color-line);
  border-radius: 14px;
  background: #fff;
}

.order-text {
  flex: 1;
  min-width: 0;
}

/* もんだいの しゅるい */
.kind {
  display: inline-block;
  padding: 1px 12px;
  border-radius: 999px;
  background: var(--color-main);
  color: #fff;
  font-size: 0.8rem;
}

.kind--change {
  background: var(--color-change);
}

.kind--tidy {
  background: var(--color-tidy);
}

.order-name {
  margin: 2px 0 0;
  font-size: 1rem;
  line-height: 1.4;
  word-break: keep-all;
}

.price {
  margin: 0;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.price small {
  margin-left: 2px;
  font-size: 1.1rem;
}

/* 「おさいふ」「だす おかね」の みだし */
.area-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 4px 4px -4px;
  font-size: 1rem;
}

.area-label span {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}

/* おさいふ（なかの おかねは main.js で ばしょを きめる） */
.wallet {
  position: relative;
  padding-top: 8px; /* main.js が おかねを おく ときに つかう */
  flex: 1 1 0; /* がめんの のこりを ぜんぶ もらう（main.js で たかすぎない ように する） */
  min-height: 120px;
  border-radius: var(--radius-medium);
  background: repeating-linear-gradient(45deg, #9b6a3c 0 14px, var(--color-leather) 14px 28px);
  box-shadow: inset 0 0 0 4px var(--color-leather-dark);
}

.wallet .money {
  position: absolute;
  rotate: var(--turn);
}

/* だす おかね */
.tray {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: center;
  flex: none;
  gap: 6px; /* main.js の TRAY_GAP と そろえる */
  overflow: hidden;
  padding: 10px; /* ふちと あわせて main.js の TRAY_FRAME と そろえる */
  border: 3px dashed rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-medium);
  background: rgba(255, 255, 255, 0.1);
}

/* おかねが おおくて おさまらない ときは、すこし ちいさく する */
.tray--tight {
  --k: 0.8;
  gap: 4px;
}

.tray:empty::before {
  content: "ここに おかねが ならぶよ";
  margin: auto;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

/* ごうけい（かんたん だけ） */
/* ごうけい（かんたん だけ。だす おかねの したに だす） */
.total-line {
  display: none; /* たかさに よゆうが ある スマホ だけ だす */
  margin: -4px 4px 0;
  font-size: 1.1rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ごうけいを だす ときは「タップで もどす」を はぶく */
.tray-hint--total {
  display: none;
}

/* たかさに よゆうが ある スマホでは、ごうけいを したの ぎょうに だして「タップで もどす」も だす */
@media (max-width: 600px) and (min-height: 701px) {
  .total-line {
    display: block;
  }

  .total-line:empty,
  .area-label .total {
    display: none;
  }

  .tray-hint--total {
    display: inline;
  }
}

.area-label .total {
  font-size: 1rem;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pay-box {
  display: flex;
  justify-content: center;
}

.pay-box .btn {
  width: 100%;
  max-width: 360px;
}

/* ===== おかねの え（ほんものに にせない、いろ と すうじ だけの え） ===== */
.money {
  /* おおきさ ＝ もとの おおきさ × --s（がめんの たかさ）× --k（「だす おかね」が いっぱいの とき） */
  --m: calc(var(--s, 1) * var(--k, 1));
  width: calc(var(--w) * var(--m));
  height: calc(var(--h, var(--w)) * var(--m));
  font-size: max(10px, calc(var(--f) * var(--m)));
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  font-family: inherit;
  font-weight: 900;
  line-height: 1;
  color: var(--color-text);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button.money {
  cursor: pointer;
  transition: transform 0.1s;
}

button.money:active {
  transform: scale(0.92);
}

button.money:focus-visible {
  outline: 3px solid var(--color-yellow);
  outline-offset: 2px;
}

button.money:disabled {
  cursor: default;
}

.coin {
  position: relative;
  border-radius: 50%;
}

.coin--1 {
  --w: 42px;
  --f: 15px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #cfd5dc);
}

.coin--5 {
  --w: 46px;
  --f: 13px;
  background: radial-gradient(circle at 35% 30%, #fff1b8, #e0b23a);
}

.coin--10 {
  --w: 48px;
  --f: 15px;
  background: radial-gradient(circle at 35% 30%, #f3b98a, #b8692f);
  color: #fff;
}

.coin--50 {
  --w: 46px;
  --f: 13px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #b9c2cc);
}

.coin--100 {
  --w: 50px;
  --f: 15px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #aeb8c4);
}

.coin--500 {
  --w: 56px;
  --f: 16px;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #d4a531);
}

/* 5えん・50えんは あなの しるし */
.coin--5::after,
.coin--50::after {
  content: "";
  position: absolute;
  top: calc(6px * var(--m));
  left: 50%;
  width: calc(9px * var(--m));
  height: calc(9px * var(--m));
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
}

.bill {
  --w: 72px;
  --h: 40px;
  --f: 15px;
  border-radius: 6px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.bill--1000 {
  background: linear-gradient(135deg, #5b8fd6, #3a66a8);
}

.bill--5000 {
  background: linear-gradient(135deg, #a77bd1, #7449a3);
}

.bill--10000 {
  --f: 14px;
  background: linear-gradient(135deg, #c9a15a, #94702f);
}

/* ===== こたえあわせ ===== */
/* おさいふの ばしょに でる。ながい ときは なかだけ スクロールする */
.feedback {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 180px;
  max-height: max-content;
  padding: 16px;
  border-radius: var(--radius-medium);
  text-align: center;
  animation: pop-in 0.3s ease-out;
}

.feedback-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
}

.feedback .btn {
  flex: none;
}

.feedback-title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1.2;
}

.feedback-title--hit {
  color: var(--color-green);
}

.feedback-title--miss {
  color: var(--color-miss);
}

.feedback-text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.answer-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-medium);
  background: #f1effb;
}

.answer-label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-sub);
  word-break: keep-all;
}

.money-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.feedback .btn {
  margin-top: 4px;
  min-width: 200px;
}

.play-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

/* ===== けっかの がめん（ほかの ゲームと おなじ かたち） ===== */
.clear-dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 40, 0.6);
  animation: fade-in 0.25s;
}

.clear-dialog[hidden] {
  display: none;
}

.clear-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 20px 24px;
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(0.3, 1.5, 0.6, 1);
}

.clear-title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1.1;
  color: var(--color-main);
  letter-spacing: 0.08em;
}

/* 「おしまい！」の まわりの ほし */
.clear-title::before,
.clear-title::after {
  content: "★";
  display: inline-block;
  margin: 0 8px;
  font-size: 0.55em;
  color: var(--color-yellow);
  vertical-align: middle;
  animation: twinkle 1.2s ease-in-out infinite;
}

.clear-title::after {
  animation-delay: 0.6s;
}

.new-record {
  margin: -6px 0 0;
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--color-pink);
  color: #fff;
  animation: pop-in 0.5s 0.2s both;
}

.result-text {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-medium);
  background: #f1effb;
  font-size: 1.05rem;
  line-height: 1.7;
  word-break: keep-all;
}

.result-number {
  font-size: 1.5em;
  font-weight: 900;
  color: var(--color-main-dark);
  font-variant-numeric: tabular-nums;
}

.clear-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* きょうしつへの ボタン（こどもが おしたく なる みため） */
.studio-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  margin-top: 4px;
  padding: 14px 16px;
  border: 3px dashed #c9c5ee;
  border-radius: var(--radius-medium);
  background: #faf9ff;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.studio-button:hover {
  border-color: var(--color-accent);
  background: #eef9ff;
}

.studio-button-main {
  font-size: 1.05rem;
  color: var(--color-text);
}

.studio-button-sub {
  font-size: 0.85rem;
  color: var(--color-accent-dark);
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.7); }
}

@keyframes twinkle {
  50% { transform: scale(1.4) rotate(20deg); }
}

/* ===== ちいさい がめん（スマホ）===== */
/* スクロール しないで 1がめんに おさまるように つめる */
@media (max-width: 600px) {
  /* この ゲームは おかねを おおきく みせる ことを さきに する。
     すきまを ひろげるのは、たかさ 700px より ひろい ときだけ（common.css の --spare を かきかえる） */
  .page--game {
    --spare: clamp(0px, 100dvh - 700px, 190px);
  }

  .rule-text {
    padding: calc(6px + var(--spare) * 4 / 190) 10px;
    font-size: calc(0.9rem + var(--spare) * 1.6 / 190);
  }

  .setting-note {
    min-height: 2.8em;
  }

  .choice-inner {
    min-height: calc(44px + var(--spare) * 8 / 190);
    font-size: calc(0.95rem + var(--spare) * 0.8 / 190);
  }

  /* もんだいは 4つ よこに ならべて、ながい なまえは 2ぎょうに する */
  .choice-list--mode {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .choice-list--mode .choice-inner {
    line-height: 1.25;
    white-space: normal;
    text-align: center;
  }

  .sp-break {
    display: inline;
  }

  .play {
    gap: calc(6px + var(--spare) * 6 / 190);
  }

  .hud-item {
    padding: calc(2px + var(--spare) * 4 / 190) 4px calc(3px + var(--spare) * 4 / 190);
  }

  .hud-label {
    font-size: calc(0.72rem + var(--spare) * 1.28 / 190);
  }

  .hud-value {
    font-size: calc(1.2rem + var(--spare) * 3.2 / 190);
  }

  .play-best {
    font-size: calc(0.8rem + var(--spare) * 1.6 / 190);
    line-height: 1.4;
  }

  .order {
    gap: 10px;
    padding: calc(6px + var(--spare) * 6 / 190) calc(10px + var(--spare) * 4 / 190);
  }

  .order-item {
    width: calc(58px + var(--spare) * 14 / 190);
    height: calc(58px + var(--spare) * 14 / 190);
    padding: 2px;
    border-width: 2px;
    border-radius: 10px;
  }

  .kind {
    padding: 0 10px;
    font-size: calc(0.72rem + var(--spare) * 1.28 / 190);
  }

  .order-name {
    margin: calc(0px + var(--spare) * 2 / 190) 0 0;
    font-size: calc(0.88rem + var(--spare) * 1.92 / 190);
    line-height: 1.3;
  }

  .price {
    font-size: calc(1.5rem + var(--spare) * 5.6 / 190);
  }

  .price small {
    font-size: 0.95rem;
  }

  /* 「おさいふ」「だす おかね」の もじは、わくの なかの うえに かさねる */
  .area-label {
    position: relative;
    z-index: 1;
    margin: 0 12px -29px; /* もじの たかさ 20px ＋ すきま 6px ＋ わくの うちがわ 3px */
    font-size: 0.85rem;
    line-height: 20px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    pointer-events: none;
  }

  .wallet {
    padding-top: 24px;
  }

  .tray {
    padding-top: 24px;
  }

  .tray:empty::before {
    margin-top: 4px;
  }

  .area-label span {
    font-size: 0.75rem;
  }

  .area-label .total {
    font-size: 0.9rem;
  }

  .pay-box .btn {
    min-height: calc(52px + var(--spare) * 8 / 190);
    font-size: calc(1.25rem + var(--spare) * 2.4 / 190);
  }

  .total-line {
    margin-top: -2px;
    font-size: 1rem;
    line-height: 1.4;
  }

  .feedback {
    gap: calc(6px + var(--spare) * 4 / 190);
    min-height: 160px;
    padding: calc(10px + var(--spare) * 6 / 190) 12px calc(12px + var(--spare) * 4 / 190);
  }

  .feedback-body {
    gap: calc(6px + var(--spare) * 4 / 190);
  }

  .feedback-title {
    font-size: calc(1.4rem + var(--spare) * 4.8 / 190);
  }

  .feedback-text {
    font-size: calc(0.9rem + var(--spare) * 1.6 / 190);
    line-height: 1.5;
  }

  .answer-box {
    gap: calc(4px + var(--spare) * 2 / 190);
    padding: calc(6px + var(--spare) * 4 / 190) 8px;
  }

  .actions {
    gap: calc(6px + var(--spare) * 4 / 190);
  }

  .play-buttons {
    gap: 8px;
    margin-top: 0;
  }

  .play-buttons .btn {
    padding: 6px 16px;
    font-size: calc(0.9rem + var(--spare) * 1.6 / 190);
  }
}

/* たかさが みじかい スマホでは、ベストの ぎょうを はぶき（せってい と けっかで みられる）、
   「しはらう」と ほかの ボタンを 1ぎょうに ならべる */
@media (max-width: 600px) and (max-height: 620px) {
  .play-best {
    display: none;
  }

  .actions {
    flex-direction: row;
  }

  .pay-box {
    flex: 1;
    order: 2;
  }

  .pay-box .btn {
    min-height: 48px;
    padding: 6px 4px;
    font-size: 1.1rem;
    white-space: nowrap;
  }

  .play-buttons {
    flex: none;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .page--game .play-buttons .btn {
    min-height: 48px;
    padding: 6px 8px;
    font-size: 0.78rem;
    white-space: nowrap;
  }
}

/* うごきを へらす せっていの ひとには、うごきを なくす */
@media (prefers-reduced-motion: reduce) {
  .feedback,
  .clear-box,
  .new-record,
  .clear-title::before,
  .clear-title::after {
    animation: none;
  }

  button.money:active {
    transform: none;
  }
}
