* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f7f5;
  --panel: #ffffff;
  --line: #d6e0da;
  --text: #2f4037;
  --muted: #6b7b72;
  --accent: #3f8061;
  --accent-dark: #30664c;
  --soft: #edf3ef;
  --danger: #a35f5f;
  --shadow: 0 8px 22px rgba(37, 68, 52, 0.08);

  --ten-bg: #e7f2e9;
  --ten-line: #7aa384;
  --ten-text: #476d51;

  --cherry-bg: #f9e7e9;
  --cherry-line: #c9858c;
  --cherry-text: #97545c;

  --calc-bg: #e5edf7;
  --calc-line: #7897bd;
  --calc-text: #486b98;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 20px 18px;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 72px;
  margin-bottom: 14px;
  padding: 7px 4px 9px;
  border-bottom: 2px solid #dfe8e2;
}

.brand {
  margin: 0 0 2px;
  font-size: 0.8rem;
  color: var(--accent-dark);
  font-weight: 800;
  letter-spacing: 0.1em;
}

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

h1 {
  margin-bottom: 0;
  display: flex;
  align-items: baseline;
  gap: 0.38em;
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  letter-spacing: 0.02em;
}

.title-name {
  color: var(--accent-dark);
}

.title-series {
  font-size: 0.68em;
  font-weight: 800;
  color: var(--text);
}

h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hidden {
  display: none !important;
}

.intro-card,
.panel,
.problem-card,
.keypad-panel,
.result-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.intro-card {
  padding: 16px;
  margin-bottom: 16px;
}

.intro-card p {
  margin-bottom: 0;
  line-height: 1.6;
}

.menu-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, 1fr);
}

.mode-button,
.choice-button,
.primary-button,
.secondary-button,
.small-button,
.key {
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.2s ease, border-color 0.2s ease;
}

.mode-button:active,
.choice-button:active,
.primary-button:active,
.secondary-button:active,
.small-button:active,
.key:active {
  transform: scale(0.97);
}

.mode-button {
  min-height: 145px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 4px 0 rgba(49, 78, 62, 0.13);
}

.mode-button:hover {
  filter: brightness(0.98);
}

.mode-ten {
  background: var(--ten-bg);
  border-color: var(--ten-line);
  color: var(--ten-text);
}

.mode-cherry {
  background: var(--cherry-bg);
  border-color: var(--cherry-line);
  color: var(--cherry-text);
}

.mode-calc {
  background: var(--calc-bg);
  border-color: var(--calc-line);
  color: var(--calc-text);
}

.mode-title {
  display: block;
  font-size: 1.32rem;
  font-weight: 800;
  margin-bottom: 10px;
}

.mode-note {
  display: block;
  line-height: 1.5;
  opacity: 0.82;
}

.panel {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

.choice-button {
  padding: 18px;
  background: #fff;
  font-weight: 800;
}

.calc-add.selected {
  background: #f4eadb;
  border-color: #c79a52;
  color: #7d5829;
}

.calc-sub.selected {
  background: #e5edf7;
  border-color: var(--calc-line);
  color: var(--calc-text);
}

.count-choice.selected {
  background: #eee7f5;
  border-color: #9a7ab7;
  color: #684f80;
}

.primary-button,
.secondary-button,
.small-button {
  min-height: 50px;
  padding: 13px 20px;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-button,
.small-button {
  background: var(--soft);
}

.small-button {
  min-width: 104px;
  border-color: #c7d6cd;
  color: var(--accent-dark);
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.status-bar > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 14px;
  text-align: center;
}

.status-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.problem-card {
  min-height: 430px;
  padding: 28px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.keypad-panel {
  min-height: 430px;
  padding: 20px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.visual-area {
  min-height: 88px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.ten-frame {
  display: grid;
  grid-template-columns: repeat(10, 32px);
  gap: 7px;
  justify-content: center;
}

.ball {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
}

.ball.filled {
  background: var(--accent);
}

.problem-area {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  width: 100%;
}

.equation,
.ten-sentence {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
  text-align: center;
}

.inline-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  height: 76px;
  padding: 4px 14px;
  border: 4px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 800;
  line-height: 1;
}

.cherry-wrap {
  display: grid;
  grid-template-rows: auto 64px auto auto;
  justify-items: center;
  width: 100%;
}

.cherry-top {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  position: relative;
  z-index: 2;
}

.cherry-lines {
  width: 230px;
  height: 64px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin-top: -4px;
  font-size: 4.4rem;
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: 0.08em;
  color: var(--text);
}

.cherry-bottom {
  display: grid;
  grid-template-columns: 96px 96px;
  column-gap: 56px;
  align-items: center;
  justify-content: center;
  margin-top: -6px;
}

.cherry-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  min-height: 76px;
  font-size: 2.7rem;
  font-weight: 800;
}

.cherry-bottom .inline-answer {
  width: 96px;
  min-width: 96px;
  height: 76px;
}

.cherry-prompt {
  margin-top: 12px;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
}

.feedback-text {
  min-height: 28px;
  margin-top: 12px;
  font-weight: 700;
}

.feedback-text.correct {
  color: var(--accent-dark);
}

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

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 390px;
}

.key {
  min-height: 76px;
  padding: 10px;
  background: linear-gradient(#fffefb, #f8f3ea);
  border: 2px solid #d8cbb9;
  border-radius: 16px;
  box-shadow: 0 4px 0 #cfc0ad, 0 8px 16px rgba(66, 52, 40, 0.06);
  font-size: 1.7rem;
  font-weight: 800;
}

.key:hover {
  border-color: var(--accent);
  filter: brightness(0.99);
}

.key:active {
  transform: translateY(3px) scale(0.99);
  box-shadow: 0 1px 0 #cfc0ad, 0 4px 8px rgba(66, 52, 40, 0.05);
}

.secondary-key {
  background: linear-gradient(#f1e8dc, #e8ddcf);
  border-color: #cbbba7;
  color: #5d5146;
  font-size: 1.05rem;
}

.ok-key {
  background: linear-gradient(#7ea089, #6f927a);
  border-color: #5f7f69;
  color: white;
  box-shadow: 0 4px 0 #55725f, 0 8px 16px rgba(66, 52, 40, 0.08);
}

.result-card {
  max-width: 620px;
  margin: 0 auto;
  padding: 32px 24px;
  text-align: center;
  border-top: 6px solid var(--accent);
}

.result-label {
  color: var(--muted);
  margin-bottom: 8px;
}

.result-card h2 {
  font-size: 2rem;
}

.result-data {
  margin: 28px 0;
  font-size: 1.35rem;
  line-height: 1.9;
}

.result-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 860px), (orientation: portrait) {
  .app-shell {
    padding: 12px;
  }

  .menu-grid {
    grid-template-columns: 1fr;
  }

  .mode-button {
    min-height: 105px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .problem-card,
  .keypad-panel {
    min-height: auto;
  }

  .problem-card {
    padding: 18px 12px;
  }

  .keypad-panel {
    padding: 12px;
  }

  .ten-frame {
    grid-template-columns: repeat(10, 24px);
    gap: 5px;
  }

  .ball {
    width: 24px;
    height: 24px;
  }

  .keypad {
    max-width: 620px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .key {
    min-height: 68px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .app-shell {
    padding-top: 8px;
  }

  .site-header {
    margin-bottom: 8px;
  }

  h1 {
    font-size: 1.65rem;
  }

  .status-bar {
    margin-bottom: 8px;
  }

  .problem-card,
  .keypad-panel {
    min-height: 345px;
  }

  .visual-area {
    min-height: 62px;
    margin-bottom: 8px;
  }

  .problem-area {
    min-height: 118px;
  }

  .key {
    min-height: 62px;
    font-size: 1.45rem;
  }

  .keypad {
    gap: 9px;
  }
}


@media (min-width: 861px) and (orientation: landscape) {
  .problem-card {
    transform: translateX(-6px);
  }

  .keypad-panel {
    transform: translateX(6px);
  }

  .problem-area {
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media (max-width: 720px) {
  .cherry-lines {
    width: 200px;
    font-size: 4rem;
  }

  .cherry-bottom {
    grid-template-columns: 84px 84px;
    column-gap: 48px;
  }

  .cherry-number,
  .cherry-bottom .inline-answer {
    width: 84px;
    min-width: 84px;
  }
}
