:root {
  --bg: #eef5fb;
  --panel: #ffffff;
  --panel-strong: #f6fbff;
  --ink: #14304a;
  --muted: #5b7187;
  --line: #d6e5f2;
  --blue: #1565c0;
  --blue-dark: #0d47a1;
  --blue-soft: #e5f1ff;
  --yellow: #ffdc5f;
  --green: #30a46c;
  --red: #d93025;
  --shadow: 0 14px 36px rgba(40, 75, 110, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  background: radial-gradient(circle at top, #ffffff 0%, var(--bg) 48%, #e7f0f8 100%);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 18px auto 8px;
  outline: none;
}

.hero {
  text-align: center;
  background: linear-gradient(135deg, #ffffff 0%, #eef8ff 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px 18px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 0.86rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  letter-spacing: 0.04em;
}

.lead {
  max-width: 760px;
  margin: 12px auto 0;
  color: var(--muted);
  line-height: 1.8;
}

.setup-panel,
.game-panel,
.result-panel {
  margin-top: 16px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.select-card {
  display: grid;
  gap: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}

.label-title {
  font-weight: 800;
  color: var(--ink);
}

select {
  width: 100%;
  border: 1px solid #b7cee1;
  border-radius: 14px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

.select-note,
.keyboard-note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.option-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.check-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.primary-btn,
.ghost-btn {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.18s ease, color 0.18s ease;
}

.primary-btn {
  display: block;
  min-width: 180px;
  margin: 0 auto;
  padding: 12px 28px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(21, 101, 192, 0.22);
}

.primary-btn:hover,
.ad-close-btn:hover {
  background: var(--blue-dark);
}

.ghost-btn {
  padding: 8px 14px;
  background: #e9f3fd;
  color: var(--blue-dark);
  border: 1px solid #c5def4;
  font-weight: 800;
}

.primary-btn:active,
.ghost-btn:active,
.ad-close-btn:active {
  transform: translateY(1px);
}

.keyboard-note {
  text-align: center;
  margin: 12px 0 0;
}

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.pill {
  background: var(--blue-soft);
  color: var(--blue-dark);
  border: 1px solid #bfdefa;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 800;
}

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

.status-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  text-align: center;
}

.status-card span,
.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-card strong,
.result-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.prompt-card {
  position: relative;
  overflow: hidden;
  margin: 14px 0;
  text-align: center;
  background: linear-gradient(180deg, #ffffff 0%, #f3f9ff 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px 12px 14px;
}

.prompt-card.error {
  animation: errorShake 0.18s linear 1;
}

.target-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.target-char {
  margin: 4px 0 2px;
  font-size: clamp(3.8rem, 11vw, 7rem);
  line-height: 1;
  font-weight: 900;
  color: var(--ink);
}

.input-guide {
  font-size: clamp(1.2rem, 3.2vw, 2.1rem);
  color: var(--blue-dark);
  font-weight: 900;
  min-height: 1.8em;
}

.finger-guide {
  color: var(--muted);
  font-weight: 800;
}

.sequence-view {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 1.15rem;
}

.seq-char {
  display: inline-grid;
  place-items: center;
  min-width: 1.6em;
  min-height: 1.6em;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--muted);
}

.seq-char.done {
  color: #ffffff;
  background: var(--green);
}

.seq-char.now {
  color: var(--ink);
  background: var(--yellow);
  border-color: #edbd22;
  font-weight: 900;
}

.visual-stage {
  display: grid;
  gap: 14px;
}

.keyboard-area,
.hands-area {
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px;
}

.keyboard-caption,
.hands-caption {
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 10px;
}

.keyboard {
  display: grid;
  gap: 7px;
  max-width: 950px;
  margin: 0 auto;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 7px;
}

.key {
  position: relative;
  min-width: clamp(34px, 7.2vw, 58px);
  height: clamp(44px, 7.5vw, 62px);
  border-radius: 12px;
  border: 1px solid #a9bfd2;
  background: linear-gradient(180deg, #ffffff 0%, #eaf2fa 100%);
  box-shadow: inset 0 -3px 0 rgba(20, 48, 74, 0.08), 0 3px 9px rgba(20, 48, 74, 0.09);
  display: grid;
  place-items: center;
  color: var(--ink);
  font-weight: 900;
  user-select: none;
}

.key.wide {
  min-width: clamp(58px, 12vw, 102px);
}

.key.space {
  min-width: clamp(160px, 40vw, 360px);
}

.key .en {
  font-size: 0.92rem;
  line-height: 1;
}

.key .kana {
  position: absolute;
  right: 6px;
  bottom: 5px;
  font-size: 0.8rem;
  color: var(--blue-dark);
}

.key.current {
  background: linear-gradient(180deg, #fff6bf 0%, #ffdc5f 100%);
  border-color: #e0ad13;
  transform: translateY(2px) scale(1.04);
  box-shadow: 0 0 0 4px rgba(255, 220, 95, 0.32), 0 9px 20px rgba(202, 145, 0, 0.18);
}

.key.pressed {
  background: linear-gradient(180deg, #d7f5e6 0%, #87ddb1 100%);
  border-color: #30a46c;
}

.key.wrong {
  background: linear-gradient(180deg, #ffd9d6 0%, #ff9f98 100%);
  border-color: var(--red);
}

.hands {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  max-width: 880px;
  margin: 0 auto;
}

.hand {
  background: #fffaf3;
  border: 1px solid #ead7bd;
  border-radius: 26px;
  padding: 12px 12px 16px;
}

.finger-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(5px, 1vw, 11px);
  min-height: 128px;
}

.finger {
  width: clamp(37px, 7vw, 64px);
  border-radius: 28px 28px 20px 20px;
  background: linear-gradient(180deg, #ffe9cc 0%, #f5c88f 100%);
  border: 1px solid #d7a86c;
  box-shadow: inset 0 -8px 12px rgba(124, 80, 33, 0.08);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 13px;
  color: #77410b;
  font-weight: 900;
  font-size: clamp(0.72rem, 1.5vw, 0.9rem);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.finger-small { height: 78px; }
.finger-ring { height: 98px; }
.finger-middle { height: 116px; }
.finger-index { height: 106px; }
.finger-thumb { height: 66px; transform: rotate(-16deg); }
.right-hand .finger-thumb { transform: rotate(16deg); }

.finger.current {
  background: linear-gradient(180deg, #fff5bc 0%, #ffdc5f 100%);
  box-shadow: 0 0 0 5px rgba(255, 220, 95, 0.32), inset 0 -8px 12px rgba(124, 80, 33, 0.08);
  transform: translateY(-6px) scale(1.04);
}

.right-hand .finger-thumb.current {
  transform: rotate(16deg) translateY(-6px) scale(1.04);
}

.left-hand .finger-thumb.current {
  transform: rotate(-16deg) translateY(-6px) scale(1.04);
}

.palm {
  height: 70px;
  max-width: 280px;
  margin: -2px auto 0;
  background: linear-gradient(180deg, #f5c88f 0%, #e9ad68 100%);
  border: 1px solid #d19a5d;
  border-radius: 26px 26px 42px 42px;
  display: grid;
  place-items: center;
  color: #77410b;
  font-weight: 900;
}

.result-panel h2 {
  margin: 0 0 12px;
  text-align: center;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.result-grid div {
  text-align: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 8px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.site-footer {
  width: min(1120px, calc(100% - 28px));
  margin: 8px auto 14px;
  text-align: center;
  color: var(--blue);
  border-top: 1px solid #d7e6f8;
  padding-top: 8px;
}

.site-footer p {
  margin: 4px 0 8px;
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 800;
}

.site-footer a:hover {
  color: var(--blue-dark);
}

.ad-panel {
  max-width: 880px;
  margin: 8px auto 0;
  padding: 0;
  border: 1px solid #d7e6f8;
  border-radius: 10px;
  background: #ffffff;
  overflow: hidden;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label,
.ad-wait {
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1.2;
}

.ad-wait {
  margin-left: auto;
}

.ad-close-btn {
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: var(--blue);
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 800;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-body {
  padding: 8px;
  background: #ffffff;
}


/* プレイ中はタイトル説明を隠し，練習画面を優先表示する */
body.play-mode {
  background: #eef5fb;
}

body.play-mode .app-shell {
  width: min(1160px, calc(100% - 12px));
  margin: 6px auto 4px;
}

body.play-mode .hero {
  display: none;
}

body.play-mode .game-panel {
  margin-top: 0;
  padding: 9px;
  border-radius: 18px;
}

body.play-mode .game-toolbar {
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 6px;
}

body.play-mode .pill,
body.play-mode .ghost-btn {
  padding: 5px 9px;
  font-size: 0.82rem;
}

body.play-mode .status-grid {
  gap: 6px;
}

body.play-mode .status-card {
  padding: 5px 6px;
  border-radius: 12px;
}

body.play-mode .status-card span {
  font-size: 0.72rem;
}

body.play-mode .status-card strong {
  margin-top: 1px;
  font-size: 1rem;
}

body.play-mode .prompt-card {
  margin: 7px 0;
  padding: 7px 8px 6px;
  border-radius: 16px;
}

body.play-mode .target-label {
  font-size: 0.72rem;
}

body.play-mode .target-char {
  margin: 0;
  font-size: clamp(2.8rem, 7.5vw, 4.8rem);
}

body.play-mode .input-guide {
  min-height: 1.3em;
  font-size: clamp(1rem, 2.2vw, 1.45rem);
}

body.play-mode .finger-guide {
  font-size: 0.9rem;
}

body.play-mode .sequence-view {
  margin-top: 5px;
  gap: 3px;
  font-size: 0.92rem;
}

body.play-mode .seq-char {
  min-width: 1.35em;
  min-height: 1.35em;
  border-radius: 8px;
}

body.play-mode .visual-stage {
  gap: 7px;
}

body.play-mode .keyboard-area,
body.play-mode .hands-area {
  padding: 7px;
  border-radius: 16px;
}

body.play-mode .keyboard-caption,
body.play-mode .hands-caption {
  margin-bottom: 4px;
  font-size: 0.78rem;
}

body.play-mode .keyboard {
  gap: 4px;
  max-width: 940px;
}

body.play-mode .key-row {
  gap: 4px;
}

body.play-mode .key {
  min-width: clamp(29px, 5.35vw, 48px);
  height: clamp(34px, 5.5vw, 45px);
  border-radius: 9px;
}

body.play-mode .key.wide {
  min-width: clamp(48px, 8.8vw, 78px);
}

body.play-mode .key.space {
  min-width: clamp(140px, 30vw, 300px);
}

body.play-mode .key .en {
  font-size: 0.78rem;
}

body.play-mode .key .kana {
  right: 4px;
  bottom: 3px;
  font-size: 0.64rem;
}

body.play-mode .hands {
  gap: 8px;
  max-width: 760px;
}

body.play-mode .hand {
  border-radius: 18px;
  padding: 6px 7px 9px;
}

body.play-mode .finger-row {
  gap: clamp(4px, 0.7vw, 8px);
  min-height: 86px;
}

body.play-mode .finger {
  width: clamp(28px, 4.8vw, 45px);
  border-radius: 20px 20px 15px 15px;
  padding-top: 8px;
  font-size: clamp(0.56rem, 1.15vw, 0.72rem);
}

body.play-mode .finger-small { height: 52px; }
body.play-mode .finger-ring { height: 66px; }
body.play-mode .finger-middle { height: 78px; }
body.play-mode .finger-index { height: 72px; }
body.play-mode .finger-thumb { height: 44px; }

body.play-mode .palm {
  height: 42px;
  max-width: 210px;
  border-radius: 18px 18px 28px 28px;
  font-size: 0.82rem;
}

body.play-mode .site-footer {
  margin-top: 4px;
  padding-top: 4px;
}

body.play-mode .site-footer p {
  margin: 2px 0 4px;
  font-size: 0.78rem;
}

@media (max-height: 780px) and (min-width: 761px) {
  body.play-mode .game-toolbar {
    position: absolute;
    right: 18px;
    top: 12px;
    z-index: 2;
  }

  body.play-mode .status-grid {
    grid-template-columns: repeat(4, minmax(90px, 1fr));
    max-width: 620px;
  }

  body.play-mode .game-panel {
    padding: 7px;
  }

  body.play-mode .prompt-card {
    margin-top: 5px;
    margin-bottom: 5px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  body.play-mode .key {
    height: clamp(31px, 4.9vw, 39px);
    min-width: clamp(27px, 4.8vw, 43px);
  }

  body.play-mode .keyboard {
    gap: 3px;
  }

  body.play-mode .key-row {
    gap: 3px;
  }

  body.play-mode .finger-row {
    min-height: 74px;
  }

  body.play-mode .finger-small { height: 45px; }
  body.play-mode .finger-ring { height: 57px; }
  body.play-mode .finger-middle { height: 68px; }
  body.play-mode .finger-index { height: 62px; }
  body.play-mode .finger-thumb { height: 38px; }

  body.play-mode .palm {
    height: 34px;
  }
}

@media (max-height: 700px) and (min-width: 761px) {
  body.play-mode .keyboard-caption,
  body.play-mode .hands-caption {
    display: none;
  }

  body.play-mode .target-char {
    font-size: clamp(2.3rem, 6.4vw, 3.8rem);
  }

  body.play-mode .prompt-card {
    display: grid;
    grid-template-columns: 88px 1fr 170px;
    align-items: center;
    gap: 8px;
    text-align: left;
  }

  body.play-mode .target-label,
  body.play-mode .sequence-view {
    display: none;
  }

  body.play-mode .target-char {
    text-align: center;
  }

  body.play-mode .input-guide,
  body.play-mode .finger-guide {
    text-align: left;
  }
}

@keyframes errorShake {
  0% { transform: translateX(0); }
  35% { transform: translateX(-7px); }
  70% { transform: translateX(7px); }
  100% { transform: translateX(0); }
}

@media (max-width: 760px) {
  .choice-grid,
  .hands,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .key-row {
    gap: 4px;
  }

  .keyboard {
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .key {
    min-width: 34px;
    height: 46px;
    border-radius: 9px;
  }

  .key .kana {
    right: 4px;
    bottom: 3px;
    font-size: 0.68rem;
  }

  .finger-row {
    min-height: 110px;
  }


  body.play-mode .app-shell {
    width: min(100% - 8px, 760px);
    margin-top: 4px;
  }

  body.play-mode .game-panel {
    padding: 7px;
  }

  body.play-mode .status-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  body.play-mode .status-card {
    padding: 4px 3px;
  }

  body.play-mode .status-card span {
    font-size: 0.62rem;
  }

  body.play-mode .status-card strong {
    font-size: 0.82rem;
  }

  body.play-mode .target-char {
    font-size: clamp(2.4rem, 14vw, 4rem);
  }

  body.play-mode .hands {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  body.play-mode .hand {
    padding: 5px;
  }

  body.play-mode .finger span {
    writing-mode: vertical-rl;
    line-height: 1;
  }

}

/* v1.2.1：初級・中級では上級入力欄を完全非表示，上級は一行表示に圧縮 */
.advanced-practice {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.advanced-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.literature-source {
  color: var(--blue-dark);
}

.advanced-remaining {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  border: 1px solid #bfdefa;
}

.advanced-target {
  padding: 8px 10px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  line-height: 1.45;
  font-size: clamp(0.98rem, 1.65vw, 1.18rem);
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
}

.advanced-input {
  width: 100%;
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  resize: none;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  border: 2px solid #b7cee1;
  border-radius: 14px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
  line-height: 1.45;
  font-size: clamp(0.98rem, 1.65vw, 1.18rem);
  outline: none;
}

.advanced-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(21, 101, 192, 0.12);
}

.advanced-input.input-error {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(217, 48, 37, 0.12);
}

.advanced-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

body.play-mode.advanced-mode .visual-stage {
  display: none;
}

body.play-mode.advanced-mode .prompt-card {
  display: block;
  text-align: center;
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
  padding-top: 6px;
  padding-bottom: 6px;
}

body.play-mode.advanced-mode .target-char {
  font-size: clamp(1.8rem, 4.3vw, 2.8rem);
}

body.play-mode.advanced-mode .input-guide {
  font-size: clamp(0.86rem, 1.7vw, 1.05rem);
}

body.play-mode.advanced-mode .finger-guide {
  font-size: 0.78rem;
}

body.play-mode.advanced-mode .advanced-target {
  height: 38px;
  max-height: 38px;
}

body.play-mode.advanced-mode .advanced-input {
  height: 46px;
  min-height: 46px;
  max-height: 46px;
}

@media (max-height: 700px) and (min-width: 761px) {
  body.play-mode.advanced-mode .prompt-card {
    display: block;
    text-align: center;
  }

  body.play-mode.advanced-mode .target-label {
    display: block;
  }

  body.play-mode.advanced-mode .advanced-target {
    height: 34px;
    max-height: 34px;
    padding: 6px 8px;
    line-height: 1.35;
  }

  body.play-mode.advanced-mode .advanced-input {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    line-height: 1.35;
  }

  body.play-mode.advanced-mode .advanced-note {
    display: none;
  }
}

/* v1.3.0：上級編は一行入力完了で自動的に次行へ進むため，表示と入力欄をさらに圧縮 */
body.play-mode.advanced-mode .advanced-head {
  margin-bottom: 0;
}

body.play-mode.advanced-mode .advanced-target {
  height: 34px;
  max-height: 34px;
  padding: 5px 8px;
  line-height: 1.35;
}

body.play-mode.advanced-mode .advanced-input {
  display: block;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  padding: 6px 8px;
  line-height: 1.35;
}
