/* タイプクエスト: レトロRPG風の見た目(オリジナル配色) */
@import url('https://fonts.googleapis.com/css2?family=DotGothic16&family=Shippori+Mincho:wght@600&display=swap');

:root {
  --bg: #0b0d1a;
  --bg2: #141833;
  --frame: #f3e9c8;      /* 窓枠: 羊皮紙色 */
  --ink: #f6f2e6;        /* 文字 */
  --muted: #9aa0c0;
  --gold: #ffd75e;
  --ok: #7cf5a8;
  --bad: #ff6b8a;
  --hp: #ff6b6b;
  --mp: #6ec3ff;
  --defend: #ffb060;
  --taunt: #d9a6ff;
  --mono: "DotGothic16", "SFMono-Regular", Menlo, Consolas, monospace;
  --font: "DotGothic16", -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  background:
    radial-gradient(ellipse at 50% 0%, #1b2050 0%, transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.015) 0 2px, transparent 2px 4px),
    var(--bg);
}
#app { max-width: 920px; margin: 0 auto; padding: 14px; min-height: 100vh; }
#app.shake { animation: shake .35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* ---- 窓 ---- */
.win {
  position: relative;
  background: rgba(8, 10, 24, .92);
  border: 3px solid var(--frame);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px var(--bg), inset 0 0 0 4px var(--frame), 0 6px 0 rgba(0,0,0,.35);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.win-title {
  position: absolute; top: -13px; left: 14px;
  background: var(--bg); color: var(--frame);
  padding: 0 8px; font-size: 13px; letter-spacing: .1em;
}
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.msg { border-left: 4px solid var(--gold); padding: 6px 12px; margin: 10px 0; background: rgba(255, 215, 94, .08); border-radius: 4px; }
.small { font-size: 13px; color: var(--muted); }
.prompt { color: var(--gold); margin-bottom: 8px; }
.gold { color: var(--gold); }
.icon-btn { background: none; border: 1px solid var(--muted); border-radius: 4px; color: var(--ink); cursor: pointer; font-size: 13px; padding: 0 5px; }

/* ---- 一枚絵 ---- */
.title-art { width: min(920px, 100%); margin: 0 auto -120px; position: relative; }
.title-art img { width: 100%; display: block; border-radius: 8px; border: 3px solid var(--frame); box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.title-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,13,26,0) 40%, rgba(11,13,26,.95) 100%); border-radius: 8px; }
.logo.over-art { position: relative; z-index: 1; }
.story-art { width: 100%; margin: 4px 0 10px; }
.story-art img { width: 100%; display: block; border-radius: 6px; border: 3px solid var(--frame); }
.stage-face.small { font-size: 48px; margin: 0 0 8px; }
.stage-face.small .portrait { width: 64px; height: 64px; }

/* ---- タイトル ---- */
.title-screen { display: flex; flex-direction: column; align-items: center; padding-top: 40px; }
.logo { text-align: center; margin-bottom: 30px; }
.emblem { font-size: 64px; filter: drop-shadow(0 0 18px rgba(255, 215, 94, .7)); animation: float 3s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.logo h1 {
  font-size: 56px; letter-spacing: .12em; margin: 4px 0 6px; line-height: 1.1;
  color: var(--gold);
  text-shadow: 0 3px 0 #8a5a00, 0 6px 0 #3a2500, 0 0 24px rgba(255, 215, 94, .45);
}
.logo h1 span { color: var(--ink); text-shadow: 0 3px 0 #4b4f7a, 0 6px 0 #1a1c33; }
.logo h1.logo-en { font-family: var(--mono); font-size: 52px; letter-spacing: .08em; }
.logo-ja { color: var(--muted); letter-spacing: .3em; font-size: 14px; margin: -2px 0 6px; }
.emblem .pix { image-rendering: pixelated; filter: drop-shadow(0 0 18px rgba(255, 215, 94, .7)); }
.tagline { color: var(--muted); letter-spacing: .06em; margin: 0; }
.name-win, .menu-win { width: min(520px, 100%); }
.name-win label { display: block; color: var(--gold); margin-bottom: 8px; }
.name-win input {
  width: 100%; font-family: var(--font); font-size: 22px; padding: 10px 12px; border-radius: 4px;
  border: 2px solid var(--muted); background: var(--bg); color: var(--ink);
}
.name-win input:focus { outline: none; border-color: var(--gold); }

/* ---- メニュー(名前を打って選ぶ) ---- */
.menu { display: flex; flex-direction: column; gap: 2px; }
.opt {
  display: grid; grid-template-columns: 18px 26px 1fr auto auto; gap: 0 10px; align-items: center;
  padding: 5px 6px; border-radius: 4px; transition: opacity .15s;
}
.opt .cur { color: var(--gold); visibility: hidden; }
.opt.alive.typing .cur { visibility: visible; animation: blink .8s steps(2, start) infinite; }
.opt.dead { opacity: .28; }
.opt.locked { opacity: .4; }
.opt-icon { text-align: center; }
.opt-label { }
.opt-guide { font-family: var(--mono); letter-spacing: .05em; color: var(--muted); }
.opt-guide .done { color: var(--ok); }
.opt.alive .opt-guide .rest { color: var(--ink); }
.opt-right { color: var(--gold); font-size: 13px; white-space: nowrap; }
.menu.compact .opt { padding: 3px 6px; }

/* ---- 打つ対象 ---- */
.target { font-size: 30px; letter-spacing: .06em; line-height: 1.45; word-break: break-all; }
.target span.done { color: var(--muted); }
.target.defend { color: var(--defend); }
.target.taunt { color: var(--taunt); }
.guide { font-family: var(--mono); font-size: 22px; margin-top: 2px; word-break: break-all; letter-spacing: .05em; }
.guide .done { color: var(--ok); }
.guide .rest { color: var(--ink); }
.miss { animation: missflash .25s; }
@keyframes missflash { 0% { background: rgba(255, 107, 138, .35); } 100% { background: transparent; } }

/* ---- 物語 ---- */
.story { display: flex; flex-direction: column; align-items: center; }
.story-head { color: var(--gold); letter-spacing: .15em; margin: 10px 0 8px; }
.stage-face { font-size: 96px; line-height: 1.1; margin: 8px 0 14px; filter: drop-shadow(0 8px 12px rgba(0,0,0,.6)); }
.story-win { width: 100%; }
.speaker { color: var(--gold); margin-bottom: 4px; }
.speaker:empty { display: none; }
.line { padding: 4px 6px; border-radius: 4px; }
.story-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ---- 物語のキーワード・チュートリアル・IME ---- */
.story-text { font-size: 24px; }
.story-text .kw { color: var(--gold); text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 3px; }
.story-text .kw .done { color: var(--muted); }
.kwlabel { color: var(--muted); font-size: 16px; }
.tutorial { margin-top: 6px; padding: 6px 10px; border-radius: 6px; background: rgba(217,166,255,.15); border: 1px dashed var(--taunt); color: var(--ink); font-size: 15px; animation: pulse .8s ease-in-out infinite alternate; }
.tutorial b { color: var(--gold); }
.ime-help { margin-top: 10px; font-size: 13px; color: #cfd3ea; line-height: 2; }
.ime-help b { color: var(--gold); }
.keycap { display: inline-block; padding: 0 8px; border: 1px solid var(--ink); border-bottom-width: 3px; border-radius: 4px; font-size: 12px; line-height: 20px; background: #1a1e3e; margin: 0 2px; }
#ime-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 10; background: #ffcf5a; color: #1a1200; padding: 10px 16px; text-align: center; font-size: 16px; display: none; }
#ime-banner .keycap { background: #fff; color: #000; border-color: #000; }

/* ---- 記録・称号・習ったキー ---- */
.rec .good, .good { color: var(--ok); }
.rec-spark { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.spark { background: rgba(0,0,0,.3); border-radius: 4px; }
.titles { margin-top: 8px; color: var(--gold); }
.key.unlearned { opacity: .28; }
.key.learned { box-shadow: inset 0 0 0 1px rgba(124,245,168,.5); }
.key.learned.home { box-shadow: inset 0 -3px 0 rgba(255,255,255,.25), inset 0 0 0 1px rgba(124,245,168,.5); }

/* ---- 町・店 ---- */
.town-head { display: grid; grid-template-columns: 1fr 200px; gap: 12px; }
.place-win .place { color: var(--gold); letter-spacing: .1em; font-size: 20px; }
.scene { font-size: 30px; letter-spacing: .2em; margin: 6px 0; }
.intro { color: #cfd3ea; margin: 4px 0 0; font-size: 15px; }
.talk { font-size: 16px; letter-spacing: 0; }
.status-win { padding: 10px 14px; }
.st-row { display: flex; justify-content: space-between; gap: 8px; }
.st-row.small { font-size: 13px; color: var(--muted); }
.st-name { color: var(--gold); }
.rec { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 14px; color: #cfd3ea; }
.rec b { color: var(--bad); }
.timerbar { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; margin: 8px 0 0; }
.timerbar .fill { height: 100%; background: var(--gold); width: 0; transition: width .04s linear; }

/* ---- 戦闘 ---- */
.battle-top { display: grid; grid-template-columns: 200px 1fr; gap: 12px; }
.lesson { font-size: 14px; color: #cfd3ea; margin-top: 6px; }
.field {
  position: relative; min-height: 120px; margin-bottom: 12px; border-radius: 8px;
  background: linear-gradient(180deg, #1a1f4a 0%, #0f1230 100%);
  border: 3px solid var(--frame); overflow: hidden;
}
.ename { letter-spacing: .1em; }
.bar { position: relative; height: 16px; background: var(--bg); border: 1px solid var(--muted); border-radius: 3px; overflow: hidden; margin: 4px auto; width: 240px; }
.bar .fill { height: 100%; transition: width .2s; }
.bar.hp .fill { background: var(--hp); }
.bar.mp .fill { background: var(--mp); }
.bar span { position: absolute; inset: 0; font-size: 11px; line-height: 16px; text-align: center; }
.log-win { min-height: 60px; font-size: 15px; color: #dfe3f5; padding: 10px 16px; }
.phase { margin-bottom: 6px; }
.p-attack { color: var(--ok); }
.p-defend { color: var(--defend); }
.p-taunt { color: var(--taunt); }
.p-menu { color: var(--gold); }
.typing-area { min-height: 84px; }
.note { border-left: 4px solid var(--gold); background: rgba(255, 215, 94, .08); padding: 8px 12px; border-radius: 4px; font-size: 14px; margin-bottom: 12px; }
.note:empty { display: none; }

/* ---- 結果 ---- */
.result h2 { margin: 4px 0 8px; color: var(--gold); font-size: 24px; }
.rank-row { display: flex; align-items: center; gap: 16px; margin: 6px 0 10px; }
.rank { font-size: 44px; line-height: 1; padding: 6px 16px; border: 3px solid currentColor; border-radius: 6px; }
.rank-S { color: var(--gold); text-shadow: 0 0 16px rgba(255, 215, 94, .8); }
.rank-A { color: var(--ok); }
.rank-B { color: var(--mp); }
.rank-C { color: var(--ink); }
.rank-D { color: var(--bad); }
.stats { border-collapse: collapse; }
.stats td { padding: 2px 18px 2px 0; }
.stats td:first-child { color: var(--muted); }

/* ---- ドット絵・フィールド・戦闘canvas ---- */
.pix { image-rendering: pixelated; image-rendering: crisp-edges; }
.portrait { width: 144px; height: 144px; }
.scene.shopkeeper .portrait { width: 64px; height: 64px; vertical-align: middle; }
.fieldwrap { position: relative; margin-bottom: 12px; border: 3px solid var(--frame); border-radius: 6px; overflow: hidden; background: #000; line-height: 0; }
.fieldwrap canvas { width: 100%; height: auto; display: block; }
.fieldwrap.parchment { border: 4px solid #6b4a2a; box-shadow: inset 0 0 0 2px #c9a86a, 0 8px 20px rgba(0,0,0,.6); background: #e6d2a3; }
.parchment .flabel {
  font-family: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif; font-weight: 600; font-size: 12px; letter-spacing: .06em;
  color: #2a1d10; background: rgba(240,228,195,.94); border: 1px solid rgba(42,29,16,.7); border-radius: 2px; padding: 0 6px;
  text-shadow: none; box-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.parchment .flabel.locked { color: #6b5a45; background: rgba(240,228,195,.75); }
.parchment .flabel.done { color: #2a6e3c; }
.parchment .flabel.secret { color: #8a6a10; }
.map-title {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); pointer-events: none;
  font-family: "Shippori Mincho", "Hiragino Mincho ProN", serif; font-weight: 600; font-size: 15px; letter-spacing: .2em; line-height: 1.4;
  color: #5a1e14; background: rgba(240,228,195,.9); border: 1.5px solid rgba(42,29,16,.8); border-radius: 3px; padding: 2px 16px;
  box-shadow: inset 0 0 0 3px rgba(240,228,195,.9), inset 0 0 0 4px rgba(42,29,16,.5);
}
.flabels { position: absolute; inset: 0; pointer-events: none; }
.flabel {
  position: absolute; transform: translate(-50%, 0); white-space: nowrap; line-height: 1.2;
  font-size: 12px; color: #fff; background: rgba(0,0,0,.6); padding: 1px 6px; border-radius: 3px;
  text-shadow: 0 1px 0 #000;
}
.flabel.done { color: var(--ok); }
.flabel.secret { color: var(--gold); }
.field { position: relative; }
.bfield { position: relative; line-height: 0; border-radius: 6px; overflow: hidden; }
.bfield canvas { width: 100%; height: auto; display: block; }
.bfield.shake { animation: shake .35s; }
.boverlay { position: absolute; inset: 0; pointer-events: none; }
.dmg {
  position: absolute; transform: translate(-50%, -50%); font-size: 26px; color: #fff; font-weight: bold;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000; animation: dmgfloat .9s ease-out forwards;
}
.dmg.bad { color: var(--bad); }
.dmg.good { color: var(--ok); }
.dmg.crit { color: var(--gold); font-size: 32px; }
.dmg.spell { color: var(--taunt); font-size: 32px; }
@keyframes dmgfloat { 0% { opacity: 0; margin-top: 10px; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: -40px; } }
.enemy-hud {
  position: absolute; top: 8px; right: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 6px; line-height: 1.3;
}
.enemy-hud .bar { width: 160px; margin: 2px 0 0; }
.face-sm { font-size: 22px; line-height: 1; }
.face-sm:empty { display: none; }

/* ---- キーボード図 ---- */
.kbd { user-select: none; cursor: pointer; margin: 4px 0 10px; }
.kbd-hidden { color: var(--muted); font-size: 13px; text-align: center; padding: 6px; border: 1px dashed var(--muted); border-radius: 4px; }
.kbd-hint { font-size: 14px; color: #cfd3ea; margin-bottom: 4px; min-height: 22px; }
.kbd-hint b { color: var(--gold); font-size: 18px; }
.kbd-row { display: flex; gap: 4px; margin-bottom: 4px; }
.kbd-row.r1 { padding-left: 20px; }
.kbd-row.r2 { padding-left: 32px; }
.kbd-row.r3 { padding-left: 44px; }
.kbd-row.r4 { padding-left: 120px; }
.key {
  width: 38px; height: 34px; line-height: 32px; text-align: center; font-family: var(--mono); font-size: 14px;
  border: 1px solid rgba(255,255,255,.22); border-bottom-width: 3px; border-radius: 4px;
  background: #1a1e3e; color: #cfd3ea;
}
.key.wide { width: 74px; }
.key.space { width: 300px; }
.key.home { box-shadow: inset 0 -3px 0 rgba(255,255,255,.25); }
.key.next { color: #111; font-weight: bold; transform: translateY(1px); border-bottom-width: 1px; animation: pulse .6s ease-in-out infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }
/* 指ごとの色。次のキーだけ塗り、それ以外は枠だけ */
.key.f-Lp, .key.f-Rp { border-color: #ff8fa3; }
.key.f-Lr, .key.f-Rr { border-color: #ffc36e; }
.key.f-Lm, .key.f-Rm { border-color: #7cf5a8; }
.key.f-Li, .key.f-Ri { border-color: #6ec3ff; }
.key.f-T { border-color: #d9a6ff; }
.key.next.f-Lp, .key.next.f-Rp { background: #ff8fa3; }
.key.next.f-Lr, .key.next.f-Rr { background: #ffc36e; }
.key.next.f-Lm, .key.next.f-Rm { background: #7cf5a8; }
.key.next.f-Li, .key.next.f-Ri { background: #6ec3ff; }
.key.next.f-T, .key.wide.next { background: #d9a6ff; }

@media (max-width: 700px) {
  body { font-size: 15px; }
  .logo h1 { font-size: 38px; }
  .target { font-size: 22px; }
  .guide { font-size: 18px; }
  .town-head, .battle-top { grid-template-columns: 1fr; }
  .field .face { font-size: 64px; }
  .opt { grid-template-columns: 14px 22px 1fr; }
  .opt-guide { grid-column: 3; }
  .opt-right { grid-column: 3; }
  .key { width: 24px; height: 26px; line-height: 24px; font-size: 11px; }
  .key.wide { width: 46px; }
  .key.space { width: 160px; }
  .kbd-row.r1 { padding-left: 10px; } .kbd-row.r2 { padding-left: 18px; } .kbd-row.r3 { padding-left: 26px; } .kbd-row.r4 { padding-left: 70px; }
}

/* ---- タッチ端末の案内 ---- */
#touch-note { display: none; position: fixed; inset: 0; z-index: 20; background: var(--bg); color: var(--ink); padding: 40px 24px; text-align: center; font-size: 18px; line-height: 2; }
#touch-note a { color: var(--ok); }
@media (hover: none) and (pointer: coarse) { #touch-note { display: block; } }
.about-link { color: var(--muted); font-size: 12px; text-decoration: none; }
.code { width: 100%; height: 70px; font-family: var(--mono); font-size: 11px; background: var(--bg); color: var(--ink); border: 1px solid var(--muted); border-radius: 4px; padding: 6px; word-break: break-all; }
.code-in { width: 100%; font-family: var(--mono); font-size: 13px; background: var(--bg); color: var(--ink); border: 2px solid var(--muted); border-radius: 4px; padding: 8px; }

/* ---- 週次レポート・カレンダー・習熟マップ ---- */
.week { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 14px; color: #cfd3ea; margin-top: 8px; }
.week .good { color: var(--ok); } .week .bad { color: var(--bad); }
.calendar { display: flex; gap: 4px; margin: 6px 0 2px; }
.cal { width: 14px; height: 14px; border-radius: 3px; background: var(--bg2); border: 1px solid var(--muted); }
.cal.on { background: var(--ok); border-color: var(--ok); }
.goal { margin-top: 6px; color: var(--gold); font-size: 14px; }
.key.heat-good { background: #17402a; } .key.heat-mid { background: #4a3a10; } .key.heat-bad { background: #4a1a26; }
.code-big { font-family: var(--mono); font-size: 20px; letter-spacing: .15em; color: var(--gold); }
