/*
  数当て（かずあて） だけの みため
  （いろなどの きほんは ../common/common.css に ある）
*/

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

.setting {
  width: 100%;
}

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

.setting-note {
  margin: 8px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text-sub);
  text-align: center;
}

/* はんいの にゅうりょく らん */
.range-inputs {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
}

.range-field {
  display: flex;
  flex: 1;
  min-width: 0;
  max-width: 150px;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.range-field-label {
  font-size: 0.85rem;
  color: var(--color-text-sub);
}

.range-input {
  width: 100%;
  height: 64px;
  padding: 0 8px;
  border: 3px solid var(--color-line);
  border-radius: var(--radius-medium);
  background: #faf9ff;
  color: var(--color-text);
  font-family: inherit;
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.range-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: #fff;
}

.range-wave {
  padding-bottom: 12px;
  font-size: 1.6rem;
  color: var(--color-text-sub);
}

/* よく つかう はんいの ボタン */
.preset-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.preset-button {
  min-height: 44px;
  padding: 4px 16px;
  border: 2px solid var(--color-line);
  border-radius: 999px;
  background: #fff;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.preset-button:hover {
  border-color: var(--color-accent);
}

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

/* かいすうの − ＋ */
.tries-view {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.tries-button {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 4px 0 var(--color-accent-dark);
  color: #fff;
  font-family: inherit;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tries-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--color-accent-dark);
}

.tries-button:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

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

.tries-label {
  min-width: 4.5em;
  margin: 0;
  font-size: 1.2rem;
  text-align: center;
}

.tries-value {
  margin-right: 4px;
  font-size: 2.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.tries-max {
  color: var(--color-text);
}

/* りれきを だす・ださない */
.choice-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

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

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

.choice-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  height: 100%;
  padding: 10px 12px;
  border: 3px solid var(--color-line);
  border-radius: var(--radius-medium);
  background: #faf9ff;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

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

.choice-card input:checked + .choice-inner {
  border-color: var(--color-main);
  background: #fff4ee;
  transform: scale(1.02);
}

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

.choice-name {
  font-size: 1.15rem;
}

.choice-desc {
  font-size: 0.8rem;
  color: var(--color-text-sub);
}

/* せっていが おかしい ときの おしらせ */
.setup-error {
  width: 100%;
  margin: -8px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  background: #ffe8ef;
  color: #c2185b;
  text-align: center;
}

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

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

/* ===== がめん2: あそぶ ===== */
.play {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  justify-items: center;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
}

.play-info,
.play-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
}

/* はんい・のこり */
.hud {
  display: flex;
  gap: 10px;
  width: 100%;
}

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

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

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

.hud-unit {
  margin-left: 2px;
  font-size: 0.6em;
}

.hud-item--left {
  background: rgba(255, 210, 63, 0.16);
}

.hud-item--left .hud-label,
.hud-item--left .hud-value {
  color: var(--color-yellow);
}

/* のこり 1かいの ときは めだたせる */
.hud-value--last {
  color: var(--color-pink) !important;
}

/* のこりの かいすうの ● */
.left-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: -4px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-yellow);
  box-shadow: 0 0 6px rgba(255, 210, 63, 0.6);
  transition: background 0.3s, box-shadow 0.3s;
}

.dot--used {
  background: rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

/* ヒントの ふきだし */
.hint {
  width: 100%;
  min-height: 84px;
  padding: 10px 16px;
  border-radius: var(--radius-large);
  background: var(--color-panel);
  color: var(--color-text);
  text-align: center;
  box-shadow: var(--shadow);
}

.hint p {
  margin: 0;
}

.hint-sub {
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--color-text-sub);
}

.hint-main {
  font-size: 1.3rem;
  line-height: 1.4;
}

/* うえ・した の ときは やじるしを つける */
.hint--up .hint-main::before {
  content: "⬆ ";
  color: var(--color-main);
}

.hint--down .hint-main::before {
  content: "⬇ ";
  color: var(--color-accent);
}

.hint--up .hint-main {
  color: var(--color-main-dark);
}

.hint--down .hint-main {
  color: var(--color-accent-dark);
}

.hint--warn {
  background: #fff7d6;
}

.hint--hit {
  background: var(--color-yellow);
}

.hint--hit .hint-main {
  font-size: 1.8rem;
}

.hint--pop {
  animation: pop 0.3s ease-out;
}

/* いれた かずの りれき */
.history-box {
  width: 100%;
}

.history-title {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.95rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* やじるしは スマホ だけで つかう */
.history-arrow {
  display: none;
}

.history-item--up {
  box-shadow: inset 4px 0 0 var(--color-main);
}

.history-item--down {
  box-shadow: inset 4px 0 0 var(--color-accent);
}

.history-item--hit {
  background: var(--color-yellow);
  color: var(--color-text);
}

/* いま いれている かず */
.guess-display {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 84px;
  border-radius: var(--radius-medium);
  background: #2b2d72;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.45);
  font-size: 3.4rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  transition: background 0.3s, box-shadow 0.3s;
}

.guess-display--empty {
  color: rgba(255, 255, 255, 0.3);
}

.guess-display--shake {
  animation: shake 0.25s;
}

/* あたった ときは きいろく ひかる */
.guess-display--hit {
  background: var(--color-yellow);
  color: var(--color-text);
  box-shadow: 0 0 0 5px #fff, 0 0 40px rgba(255, 210, 63, 0.7);
  animation: pop 0.5s ease-out;
}

.guess-display--miss {
  color: rgba(255, 255, 255, 0.55);
}

/* でんたくの ような ボタン */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.key {
  height: 60px;
  border: none;
  border-radius: var(--radius-medium);
  background: #fff;
  box-shadow: 0 5px 0 #c9c5ee;
  color: var(--color-text);
  font-family: inherit;
  font-size: 1.9rem;
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s;
}

.key:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c9c5ee;
}

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

.key:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

/* 0 は よこに ながく する（でんたくと おなじ） */
.key--zero {
  grid-column: span 2;
}

.key--delete {
  background: #f1effb;
  font-size: 1.2rem;
}

.key-submit {
  grid-column: 1 / -1;
  margin-top: 4px;
}

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

.play-buttons {
  display: flex;
  justify-content: center;
}

/* ひろい がめん（パソコン）では ひだりに ヒント、みぎに ボタンを ならべる */
@media (min-width: 860px) {
  .play {
    grid-template-columns: 1fr 1fr;
    align-items: start;
    column-gap: 40px;
  }

  .play-info {
    justify-self: end;
  }

  .play-input {
    justify-self: start;
  }

  .play-buttons {
    grid-column: 1 / -1;
  }
}

/* マウスの ない スマホでは、キーボードの せつめいは いらない */
@media (hover: none) {
  .play-hint {
    display: none;
  }
}

/* ===== おわりの がめん ===== */
.end-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;
}

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

.end-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  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);
}

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

/* 「あたり！」の まわりの ほし */
.end-title::before,
.end-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;
}

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

/* ざんねんの ときは ほしを ださず、いろも おちついた いろに する */
.end-box--miss .end-title {
  color: var(--color-accent-dark);
}

.end-box--miss .end-title::before,
.end-box--miss .end-title::after {
  content: none;
}

.end-message {
  margin: -4px 0 0;
  font-size: 1.2rem;
}

.result {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.result-item {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 8px;
  border-radius: var(--radius-medium);
  background: #f1effb;
}

.result-label {
  font-size: 0.85rem;
  color: var(--color-text-sub);
}

.result-value {
  font-size: 1.8rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.end-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 shake {
  25% { transform: translateX(-3%); }
  75% { transform: translateX(3%); }
}

@keyframes pop {
  50% { transform: scale(1.05); }
}

@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) {
  /* せっていの がめん */
  .range-field-label {
    font-size: calc(0.75rem + var(--spare) * 1.6 / 190);
  }

  .range-input {
    height: calc(48px + var(--spare) * 12 / 190);
    font-size: calc(1.6rem + var(--spare) * 6.4 / 190);
  }

  .range-wave {
    padding-bottom: 6px;
  }

  .preset-list {
    margin-top: calc(8px + var(--spare) * 4 / 190);
  }

  .tries-view {
    gap: 14px;
  }

  .tries-button {
    width: calc(48px + var(--spare) * 8 / 190);
    height: calc(48px + var(--spare) * 8 / 190);
    font-size: 1.6rem;
  }

  .tries-value {
    font-size: calc(2rem + var(--spare) * 6.4 / 190);
  }

  .choice-list {
    gap: 8px;
  }

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

  .choice-name {
    font-size: calc(1rem + var(--spare) * 1.6 / 190);
  }

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

  .setup-error {
    margin: 0;
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .setup-record {
    padding: calc(4px + var(--spare) * 4 / 190) 14px;
    font-size: calc(0.85rem + var(--spare) * 1.6 / 190);
  }

  /* あそぶ がめん（いれた かずが ふえたら、ボタンを すこし ひくく して おさめる） */
  .play {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(8px + var(--spare) * 6 / 190);
  }

  .play-input {
    flex: 1 1 0;
  }

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

  /* はんい・のこり は、なまえ と かずを よこに ならべる */
  .hud {
    gap: 8px;
  }

  .hud-item {
    flex-direction: row;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    padding: calc(4px + var(--spare) * 4 / 190) 8px;
  }

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

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

  .left-dots {
    gap: 5px;
    margin-top: -2px;
  }

  .dot {
    width: calc(10px + var(--spare) * 3 / 190);
    height: calc(10px + var(--spare) * 3 / 190);
  }

  .hint {
    min-height: calc(60px + var(--spare) * 18 / 190);
    padding: calc(6px + var(--spare) * 4 / 190) 12px;
    border-radius: var(--radius-medium);
  }

  .hint-sub {
    font-size: calc(0.78rem + var(--spare) * 1.6 / 190);
  }

  .hint-main {
    font-size: calc(1.05rem + var(--spare) * 3.2 / 190);
  }

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

  .history-title {
    margin-bottom: 2px;
  }

  .history-list {
    gap: 4px;
    min-height: 26px;
  }

  .history-item {
    padding: 0 8px 0 10px;
    font-size: 0.85rem;
  }

  .guess-display {
    height: clamp(48px, 9dvh, 84px);
    font-size: clamp(2.2rem, 6dvh, 3.4rem);
  }

  /* でんたくの ならび（たかさに あわせて ボタンを のばしたり ちぢめたり する） */
  .keypad {
    flex: 1 1 auto;
    grid-template-rows: repeat(4, minmax(44px, 1fr)) auto;
    gap: 6px; /* main.js の KEY_GAP と そろえる */
    max-height: 340px; /* すうじの ボタン 64px × 4だん まで */
  }

  .key {
    height: auto;
    min-height: 44px;
    font-size: calc(1.6rem + var(--spare) * 4.8 / 190);
  }

  .key-submit {
    min-height: 52px; /* main.js の SUBMIT_HEIGHT と そろえる */
    margin-top: 0;
    font-size: calc(1.25rem + var(--spare) * 1.6 / 190);
  }

  .play-hint {
    display: none;
  }

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

  /* ===== はみだす ときだけ（main.js で きりかえる） ===== */

  /* いれた かずが おおい とき:「9000⬇」の みじかい かたちに して、みだしも はぶく */
  .play--short-history .history-title {
    display: none;
  }

  .play--short-history .history-arrow {
    display: inline;
    margin-left: 2px;
  }

  .play--short-history .history-item--up .history-arrow {
    color: var(--color-main);
  }

  .play--short-history .history-item--down .history-arrow {
    color: var(--color-accent);
  }

  .play--short-history .history-word {
    display: none;
  }

  /* たかさが たりない とき: ボタンを 1〜5・6〜0 の 2だんに して、「けす」と「これに する！」を したに ならべる */
  .play--keys-2rows .keypad {
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: 1fr 1fr auto;
    min-height: 152px; /* すうじの ボタン 44px × 2だん ＋「これに する！」52px ＋ すきま */
    max-height: 200px; /* すうじの ボタン 68px × 2だん まで */
  }

  .play--keys-2rows .key[data-digit="1"] { order: 1; }
  .play--keys-2rows .key[data-digit="2"] { order: 2; }
  .play--keys-2rows .key[data-digit="3"] { order: 3; }
  .play--keys-2rows .key[data-digit="4"] { order: 4; }
  .play--keys-2rows .key[data-digit="5"] { order: 5; }
  .play--keys-2rows .key[data-digit="6"] { order: 6; }
  .play--keys-2rows .key[data-digit="7"] { order: 7; }
  .play--keys-2rows .key[data-digit="8"] { order: 8; }
  .play--keys-2rows .key[data-digit="9"] { order: 9; }
  .play--keys-2rows .key[data-digit="0"] { order: 10; }

  .play--keys-2rows .key--zero {
    grid-column: auto;
  }

  .play--keys-2rows .key--delete {
    order: 11;
    height: 52px;
    font-size: 1rem;
    white-space: nowrap;
  }

  .play--keys-2rows .key-submit {
    order: 12;
    grid-column: span 4;
  }
}

/* たかさが みじかい スマホでは、もっと つめる */
@media (max-width: 600px) and (max-height: 620px) {
  .page--game .setup {
    gap: 10px;
  }

  /* 「はじめ」「おわり」は「〜」で わかるので はぶく */
  .range-field-label {
    display: none;
  }

  .range-input {
    height: 44px;
  }
}
