:root {
  --ink: #4a3826; --paper: rgba(255, 253, 244, 0.93); --line: #fff; --green: #56b947; --green-d: #2f8a34;
  --orange: #ff8a3c; --red: #ff5a6a; --blue: #3fa9f5; --shadow: 0 4px 0 rgba(60, 40, 20, 0.18), 0 8px 18px rgba(40, 60, 90, 0.18);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9bd6ff; color: var(--ink);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif; font-weight: 700;
  user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

/* ロゴ */
.logo { display: flex; flex-direction: column; align-items: center; line-height: 1; filter: drop-shadow(0 6px 0 rgba(40, 80, 40, 0.25)); }
.logo .l1 { font-size: clamp(44px, 9vw, 96px); font-weight: 900; color: #6fd24f; -webkit-text-stroke: clamp(8px, 1.4vw, 14px) #fff; paint-order: stroke fill; letter-spacing: 0.04em; }
.logo .l2 { font-size: clamp(30px, 6vw, 62px); font-weight: 900; color: var(--orange); -webkit-text-stroke: clamp(7px, 1.1vw, 11px) #fff; paint-order: stroke fill; margin-top: -0.08em; letter-spacing: 0.2em; padding-left: 0.2em; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 16px; z-index: 30; }
#loading { background: linear-gradient(#6ec3ff, #c9ecff 60%, #b6e79a 60%, #8fd66f); }
#loading .bar { width: min(420px, 78vw); height: 22px; border-radius: 99px; background: #fff; border: 4px solid #fff; box-shadow: var(--shadow); overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #8fe06a, #56b947); transition: width 0.15s; }
#loadtext { margin: 0; font-size: 18px; color: #2c5f8a; text-align: center; max-width: 90vw; }
#loadtext.err { color: #c0392b; background: #fff; padding: 12px 18px; border-radius: 14px; }
#loadnote { margin: 10px 0 0; font-size: 14px; color: #2c5f8a; opacity: 0.8; text-align: center; max-width: 90vw; }

#title { justify-content: space-between; padding: 4vh 16px 3vh; background: linear-gradient(rgba(120, 200, 255, 0.25), rgba(255, 255, 255, 0) 45%); }
.card { background: var(--paper); border: 5px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); padding: 18px 22px; text-align: center; max-width: min(680px, 94vw); }
.card .lead { margin: 0 0 10px; font-size: 20px; }
.chars { display: flex; gap: 14px; justify-content: center; margin-bottom: 14px; }
.char { width: 150px; padding: 8px 8px 10px; background: #fff; border: 5px solid #e6dcc6; border-radius: 22px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 18px; transition: transform 0.1s; }
.char img { width: 112px; height: 112px; object-fit: contain; }
.char.sel { border-color: var(--green); background: #f0ffe6; transform: translateY(-4px) scale(1.04); box-shadow: 0 6px 0 var(--green-d); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
button.big { font-size: 20px; padding: 12px 26px; border-radius: 99px; background: #fff; border: 4px solid #e6dcc6; box-shadow: 0 4px 0 #cbbf9f; }
button.big.primary { background: var(--green); border-color: #fff; color: #fff; box-shadow: 0 5px 0 var(--green-d); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); font-size: 24px; padding: 12px 40px; }
button.big:active { transform: translateY(3px); box-shadow: 0 1px 0 #cbbf9f; }
.keys { font-size: 13px; line-height: 1.8; margin: 14px 0 0; opacity: 0.85; }
.keys b { background: #fff; border: 2px solid #e0d6bf; border-radius: 7px; padding: 0 6px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#tl { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
#hearts { font-size: 26px; letter-spacing: 1px; filter: drop-shadow(0 2px 0 #fff) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25)); min-height: 30px; }
#hearts .off { filter: grayscale(1) opacity(0.35); }
#stamina { width: 150px; height: 13px; border-radius: 99px; background: rgba(255, 255, 255, 0.85); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); overflow: hidden; opacity: 0; transition: opacity 0.3s; }
#stamina.show { opacity: 1; }
#stamina i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffd84a, #8fe06a); border-radius: 99px; }
#stamina.low i { background: #ff7a5a; }
#counters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--paper); border: 3px solid #fff; border-radius: 99px; padding: 3px 12px 3px 9px; font-size: 16px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18); white-space: nowrap; }
#carry { background: #fff3c9; }
#quest { position: absolute; right: 14px; top: 12px; width: min(320px, 44vw); background: var(--paper); border: 4px solid #fff; border-radius: 20px; padding: 9px 14px 10px; box-shadow: var(--shadow); }
#quest .qt { font-size: 15px; color: var(--orange); font-weight: 900; }
#quest .qt::before { content: "◆ "; }
#quest .qd { font-size: 16px; line-height: 1.45; margin-top: 2px; }
#mapwrap { position: absolute; left: 14px; bottom: 14px; width: 176px; height: 176px; }
#minimap { width: 176px; height: 176px; border-radius: 50%; border: 5px solid #fff; box-shadow: var(--shadow); background: #5bb8ea; display: block; }
#clock { position: absolute; left: 50%; top: -14px; transform: translateX(-50%); background: var(--paper); border: 3px solid #fff; border-radius: 99px; padding: 1px 10px; font-size: 13px; white-space: nowrap; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); }
#region { position: absolute; left: 50%; top: 13%; transform: translateX(-50%); font-size: clamp(26px, 4.2vw, 44px); font-weight: 900; color: #fff; -webkit-text-stroke: 7px rgba(60, 110, 60, 0.85); paint-order: stroke fill; opacity: 0; transition: opacity 0.8s; white-space: nowrap; letter-spacing: 0.08em; }
#region.show { opacity: 1; }
#toasts { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: 90vw; }
.toast { background: var(--paper); border: 4px solid #fff; border-radius: 99px; padding: 7px 22px; font-size: 19px; box-shadow: var(--shadow); animation: pop 0.25s ease-out; transition: opacity 0.5s, transform 0.5s; text-align: center; }
.toast.big { font-size: 26px; background: #fff7d1; border-color: #ffd84a; padding: 10px 30px; }
.toast.out { opacity: 0; transform: translateY(-12px); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.08); } to { transform: scale(1); opacity: 1; } }
#prompt { position: absolute; left: 50%; bottom: 23%; transform: translateX(-50%); background: var(--paper); border: 4px solid #fff; border-radius: 99px; padding: 6px 20px 6px 8px; font-size: 20px; box-shadow: var(--shadow); white-space: nowrap; display: flex; align-items: center; gap: 9px; }
#prompt kbd { font: inherit; background: var(--orange); color: #fff; border-radius: 50%; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 3px 0 #d96a1e; }
#bosshp { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: min(460px, 60vw); text-align: center; }
#bosshp span { font-size: 18px; color: #fff; -webkit-text-stroke: 5px #7a2a4a; paint-order: stroke fill; }
#bosshp div { height: 18px; border-radius: 99px; background: rgba(255, 255, 255, 0.85); border: 4px solid #fff; overflow: hidden; box-shadow: var(--shadow); }
#bosshp i { display: block; height: 100%; background: linear-gradient(90deg, #ff5a6a, #ff9a5a); border-radius: 99px; transition: width 0.2s; }
#vinfo { position: absolute; right: 14px; bottom: 76px; background: var(--paper); border: 4px solid #fff; border-radius: 18px; padding: 6px 14px; font-size: 15px; box-shadow: var(--shadow); text-align: right; line-height: 1.5; }
#hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(40, 60, 80, 0.55); color: #fff; border-radius: 99px; padding: 4px 16px; font-size: 14px; transition: opacity 0.6s; white-space: nowrap; }
#hint.off { opacity: 0; }
#btns { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; pointer-events: auto; }
#btns button { width: 52px; height: 52px; border-radius: 50%; background: var(--paper); border: 4px solid #fff; font-size: 24px; box-shadow: var(--shadow); padding: 0; }

/* かいわ */
#dialog { position: fixed; left: 50%; bottom: 4vh; transform: translateX(-50%); width: min(760px, 94vw); background: var(--paper); border: 5px solid #fff; border-radius: 26px; box-shadow: var(--shadow); padding: 26px 26px 20px; z-index: 20; cursor: pointer; min-height: 132px; }
#dialog .name { position: absolute; left: 22px; top: -20px; background: var(--green); color: #fff; border: 4px solid #fff; border-radius: 99px; padding: 2px 18px; font-size: 18px; box-shadow: 0 3px 0 var(--green-d); }
#dialog .text { font-size: 22px; line-height: 1.6; min-height: 70px; white-space: pre-wrap; }
#dialog .next { position: absolute; right: 22px; bottom: 10px; color: var(--orange); font-size: 20px; animation: bob 0.7s infinite alternate; }
@keyframes bob { to { transform: translateY(5px); } }
#dialog .choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
#dialog .choices button { text-align: left; font-size: 19px; padding: 9px 18px; border-radius: 16px; background: #fff; border: 3px solid #e6dcc6; }
#dialog .choices button:hover, #dialog .choices button.sel { border-color: var(--green); background: #f0ffe6; }
#dialog .choices button[disabled] { opacity: 0.45; }

/* パネル */
.panel { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--paper); border: 6px solid #fff; border-radius: 30px; box-shadow: 0 0 0 100vmax rgba(30, 50, 70, 0.45), var(--shadow); padding: 16px 20px 20px; z-index: 25; max-width: 94vw; max-height: 94vh; overflow: auto; }
.phead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 20px; }
.phead h2 { margin: 0; font-size: 24px; font-weight: 900; color: var(--green-d); }
.close { width: 42px; height: 42px; border-radius: 50%; background: var(--red); color: #fff; font-size: 20px; box-shadow: 0 3px 0 #c93a4a; flex: none; }
#mapcanvas { width: min(74vh, 86vw); height: min(74vh, 86vw); border-radius: 18px; display: block; background: #5bb8ea; }
.note { margin: 8px 0 0; font-size: 14px; text-align: center; opacity: 0.8; }
#bookgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(640px, 86vw); }
.fr { background: #fff; border: 4px solid #e6dcc6; border-radius: 18px; padding: 6px 4px 8px; text-align: center; font-size: 14px; line-height: 1.3; }
.fr img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; display: block; }
.fr.no img { filter: brightness(0) opacity(0.22); }
.fr.no span { opacity: 0.5; }
.fr small { display: block; font-size: 11px; opacity: 0.7; font-weight: 700; }
.mlist { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(520px, 84vw); }
.mlist .primary { grid-column: 1 / -1; }
.help { margin-top: 14px; font-size: 14px; line-height: 1.8; background: #fff; border-radius: 16px; padding: 10px 14px; }

/* タッチそうさ */
#touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#stick { position: absolute; left: 26px; bottom: 210px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); border: 4px solid rgba(255, 255, 255, 0.8); pointer-events: auto; }
#stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3); }
.tb { position: absolute; width: 70px; height: 70px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); border: 4px solid #fff; font-size: 28px; pointer-events: auto; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25); padding: 0; }
.tb.on { background: #ffe48a; }
#t-fire { right: 24px; bottom: 170px; }
#t-jump { right: 108px; bottom: 96px; }
#t-act { right: 24px; bottom: 82px; background: var(--orange); color: #fff; }
#t-run { right: 108px; bottom: 182px; }

#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity 0.45s; z-index: 40; }
#fade.on { opacity: 1; }

@media (max-width: 720px) {
  #quest { width: 46vw; padding: 6px 10px; } #quest .qd { font-size: 13px; } #quest .qt { font-size: 12px; }
  #mapwrap, #minimap { width: 120px; height: 120px; } #hint { display: none; } .chip { font-size: 13px; } #hearts { font-size: 20px; }
  #dialog .text { font-size: 18px; } .char { width: 120px; } .char img { width: 84px; height: 84px; } .keys { display: none; }
  #bookgrid { grid-template-columns: repeat(3, 1fr); }
}

/* 日本全国版の追加 */
#region small { display: block; font-size: 0.45em; letter-spacing: 0.3em; margin-top: -0.2em; -webkit-text-stroke: 5px rgba(60, 110, 60, 0.85); paint-order: stroke fill; text-align: center; }
#region { text-align: center; line-height: 1.15; }
#quest .qd { white-space: pre-line; }
.float { position: absolute; transform: translate(-50%, -50%); font-size: 22px; font-weight: 900; -webkit-text-stroke: 4px #fff; paint-order: stroke fill; pointer-events: none; white-space: nowrap; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { font-size: 17px; padding: 8px 16px; border-radius: 99px; background: #fff; border: 3px solid #e6dcc6; }
.tab.on { background: var(--green); color: #fff; border-color: #fff; box-shadow: 0 3px 0 var(--green-d); }
#bookgrid { max-height: 70vh; overflow: auto; padding: 2px; }
#bookgrid.stamps { grid-template-columns: repeat(8, 1fr); gap: 6px; width: min(860px, 90vw); }
.fr.st { padding: 4px 2px 6px; font-size: 12px; border-width: 3px; border-radius: 14px; }
.fr.st .em { font-size: 30px; line-height: 1.35; }
.fr.st:not(.no) { border-color: #9ad27a; background: #f3ffe9; }
.fr.st.no .em { filter: grayscale(1) opacity(0.35); }
.fr.st small { font-size: 10px; }
#mapcanvas { cursor: pointer; }
#counters { max-width: 46vw; }
@media (max-width: 720px) { #bookgrid.stamps { grid-template-columns: repeat(5, 1fr); } }

/* 名産ミニゲーム */
#hud.mg #quest, #hud.mg #region, #hud.mg #counters, #hud.mg #carry, #hud.mg #hint { display: none; }
#minihud { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: min(540px, 92vw); background: var(--paper); border: 4px solid #ffd84a; border-radius: 22px; padding: 6px 16px 8px; box-shadow: var(--shadow); text-align: center; }
#minihud .mt { font-size: 19px; font-weight: 900; color: #c0552a; }
#minihud .mrow { display: flex; align-items: center; gap: 10px; font-size: 18px; margin-top: 2px; white-space: nowrap; }
#minihud .mbar { flex: 1; height: 14px; border-radius: 99px; background: #eee3c8; overflow: hidden; }
#minihud .mbar i { display: block; height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, #ffb13c, #ffd84a); }
#minihud .mscore { font-weight: 900; color: var(--green-d); font-size: 22px; min-width: 4.2em; text-align: right; }
#minihud .mtime { min-width: 6.6em; text-align: left; }
#minihud .mhelp { font-size: 13px; opacity: 0.8; margin-top: 2px; }
#minibig { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(56px, 12vw, 140px); font-weight: 900; color: #ffd84a; -webkit-text-stroke: 14px #c0552a; paint-order: stroke fill; white-space: nowrap; z-index: 2; }
#minibig.pop { animation: bigpop 0.3s ease-out; }
@keyframes bigpop { from { transform: translate(-50%, -50%) scale(2.1); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#minipanel { position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%); width: min(720px, 94vw, 118vh); border: 6px solid #fff; border-radius: 26px; overflow: hidden; box-shadow: 0 0 0 100vmax rgba(30, 50, 70, 0.4), var(--shadow); }
#minicv { display: block; width: 100%; height: auto; }
.fr.st .star { display: block; font-style: normal; font-size: 11px; color: #f0a800; letter-spacing: 1px; line-height: 1.2; }
.fr.st .star.zero { color: #cdbf9f; }
.mlist .wide { grid-column: 1 / -1; background: #fff3c9; }
@media (max-width: 720px) { #minihud { top: 40px; } #minihud .mhelp { display: none; } }

/* タッチそうさ (スマホ・タブレット) の ときの 表示 */
.tkeys { display: none; font-size: 13px; line-height: 1.8; margin: 12px 0 0; opacity: 0.85; }
.tkeys b { background: #fff; border: 2px solid #e0d6bf; border-radius: 7px; padding: 0 5px; }
.thelp { display: none; }
body.touch .keys, body.touch .khelp, body.touch #hint { display: none; }
body.touch .tkeys, body.touch .thelp { display: block; }
body.touch #vinfo { right: auto; left: 50%; bottom: 10px; transform: translateX(-50%); text-align: center; white-space: nowrap; }
#title { overflow-y: auto; touch-action: pan-y; }

/* よこむきの スマホ など、たかさが ひくい 画面 */
@media (max-height: 520px) {
  #title { flex-direction: row; justify-content: center; align-items: flex-start; gap: 3vw; padding: 8px 14px; }
  #title > * { margin-top: auto; margin-bottom: auto; }
  .logo .l1 { font-size: clamp(34px, 7vw, 56px); -webkit-text-stroke-width: 8px; }
  .logo .l2 { font-size: clamp(24px, 4.6vw, 38px); -webkit-text-stroke-width: 7px; }
  .card { padding: 10px 14px; border-radius: 20px; border-width: 4px; flex: 0 1 440px; min-width: 0; }
  .card .lead { font-size: 14px; margin-bottom: 6px; }
  .chars { gap: 10px; margin-bottom: 8px; }
  .char { width: 104px; padding: 4px 6px 6px; font-size: 14px; border-width: 4px; border-radius: 16px; }
  .char img { width: 64px; height: 64px; }
  button.big { font-size: 16px; padding: 8px 18px; }
  button.big.primary { font-size: 19px; padding: 8px 30px; }
  .keys, .tkeys { font-size: 11px; margin-top: 8px; line-height: 1.6; }

  #tl { left: 10px; top: 8px; gap: 4px; }
  #hearts { font-size: 18px; min-height: 22px; }
  #stamina { width: 110px; height: 10px; border-width: 2px; }
  .chip { font-size: 12px; padding: 2px 9px 2px 7px; border-width: 2px; }
  #quest { right: 10px; top: 8px; width: min(280px, 40vw); padding: 5px 10px 6px; border-radius: 14px; border-width: 3px; }
  #quest .qt { font-size: 11px; }
  #quest .qd { font-size: 12px; line-height: 1.35; }
  #mapwrap { left: 150px; bottom: 10px; }
  #mapwrap, #minimap { width: 84px; height: 84px; }
  #minimap { border-width: 3px; }
  #clock { font-size: 11px; top: -12px; padding: 0 8px; border-width: 2px; }
  #region { top: 20%; font-size: clamp(22px, 4vw, 34px); }
  #toasts { top: 36%; }
  .toast { font-size: 15px; padding: 5px 16px; border-width: 3px; }
  .toast.big { font-size: 19px; padding: 7px 22px; }
  #prompt { bottom: 30%; font-size: 16px; padding: 4px 16px 4px 6px; border-width: 3px; }
  #prompt kbd { width: 28px; height: 28px; }
  #bosshp { top: auto; bottom: 6px; width: 34vw; }
  #bosshp span { font-size: 14px; }
  #bosshp div { height: 13px; border-width: 3px; }
  #btns { right: 10px; bottom: 8px; gap: 6px; }
  #btns button { width: 42px; height: 42px; font-size: 19px; border-width: 3px; }
  #vinfo { font-size: 12px; padding: 3px 10px; border-width: 3px; border-radius: 12px; line-height: 1.4; }
  #stick { left: 16px; bottom: 16px; width: 116px; height: 116px; }
  #stick i { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
  .tb { width: 62px; height: 62px; font-size: 24px; }
  #t-act { right: 14px; bottom: 60px; }
  #t-jump { right: 84px; bottom: 60px; }
  #t-fire { right: 14px; bottom: 130px; }
  #t-run { right: 84px; bottom: 130px; }

  #dialog { bottom: 6px; width: min(620px, 78vw); padding: 18px 16px 10px; min-height: 84px; border-radius: 18px; border-width: 4px; }
  #dialog .name { font-size: 14px; top: -16px; left: 16px; border-width: 3px; padding: 1px 14px; }
  #dialog .text { font-size: 16px; line-height: 1.45; min-height: 46px; }
  #dialog .next { font-size: 15px; right: 14px; bottom: 5px; }
  #dialog .choices { gap: 5px; margin-top: 6px; }
  #dialog .choices button { font-size: 15px; padding: 6px 14px; border-radius: 12px; }

  .panel { padding: 10px 12px 12px; border-radius: 20px; border-width: 4px; max-height: 96vh; }
  .phead { margin-bottom: 6px; }
  .phead h2 { font-size: 18px; }
  .close { width: 34px; height: 34px; font-size: 16px; }
  .tab { font-size: 14px; padding: 5px 12px; }
  #mapcanvas { width: min(66vh, 86vw); height: min(66vh, 86vw); }
  .note { display: none; }
  #bookgrid { max-height: 64vh; }
  .mlist { gap: 6px; }
  .help { font-size: 12px; margin-top: 8px; padding: 6px 10px; line-height: 1.6; }

  #minihud { top: 4px; width: min(430px, 58vw); padding: 3px 12px 5px; border-width: 3px; border-radius: 16px; }
  #minihud .mt { font-size: 14px; }
  #minihud .mrow { font-size: 14px; }
  #minihud .mscore { font-size: 17px; }
  #minihud .mhelp { display: block; font-size: 11px; }
  #minibig { font-size: clamp(44px, 16vh, 90px); -webkit-text-stroke-width: 10px; }
}