:root {
  --bg: #dcefe4;
  --panel: #1f2a3a;
  --panel-2: #2f3d52;
  --text-dark: #1f2a3a;
  --text-light: #f4f1e6;
  --accent: #2e9e6a;
  --accent-dark: #1f7a50;
  --paper: #fbf7ea;
  --paper-2: #ece4cc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: var(--bg);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--text-dark);
  padding: 12px 16px 24px;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }

.container { width: 100%; max-width: 720px; }

.back-to-top {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-dark);
  text-decoration: none;
}
.back-to-top:hover { text-decoration: underline; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
h1 { font-size: 26px; margin: 0; font-weight: 800; }
.header-buttons { display: flex; gap: 6px; }

.small-btn {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  background: var(--panel);
  color: var(--text-light);
}
.small-btn:hover { background: var(--panel-2); }

/* ---------- ステータス ---------- */

.status-bar {
  background: var(--panel);
  color: var(--text-light);
  border-radius: 8px 8px 0 0;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 14px;
}
.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 14px;
}
.status-row + .status-row { margin-top: 3px; }
.st-place { color: #ffe08a; font-size: 15px; }
.st-time { color: #b9d4ff; }
.st-lv { color: #ffe08a; }
.st-gauge { display: inline-flex; align-items: center; gap: 5px; }
.bar-bg {
  display: inline-block;
  width: 56px;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.bar-fill { display: block; height: 100%; width: 100%; transition: width 0.15s; }
.bar-fill.hp { background: #5ad17a; }
.bar-fill.mp { background: #6aa8ff; }
.warn { color: #ff8a8a; }

/* ---------- ゲーム画面 ---------- */

.board-wrap {
  position: relative;
  background: #000;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
#game-canvas { display: block; width: 100%; image-rendering: pixelated; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* なぞって あるく ときの スティック(ゆびを おいた ところに でる) */
.stick {
  position: absolute;
  width: 84px; height: 84px;
  margin: -42px 0 0 -42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(20, 15, 30, 0.25);
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.stick-knob {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(254, 231, 97, 0.85);
  border: 3px solid #1b1524;
}

.msg-log {
  padding: 6px 12px;
  background: #11141f;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-light);
  font-size: 13px;
  line-height: 1.45;
  height: calc(1.45em * 3 + 12px);
  overflow: hidden;
}
/* ショートカット: がめんの したの 8つの わく(Elona ふう。ばんごうは ひだりうえ、かずは みぎした) */
/* ショートカットの たかさ(がめんの おおきさの けいさんに つかう) */
:root { --hot: 46px; --hot-h: calc(var(--hot) + 11px); }
@media (max-width: 480px) { :root { --hot: 40px; } }
.hotbar {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, var(--hot)));
  justify-content: center;
  gap: 3px;
  padding: 4px 6px 5px;
  background: linear-gradient(#3b2c1f, #2a1f16);
  border-top: 2px solid #5b4330;
}
.hot-cell {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid #6b5138;
  border-radius: 5px;
  background: radial-gradient(#3e4f3a, #26301f);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.hot-cell .item-icon { width: 66%; height: 66%; image-rendering: pixelated; pointer-events: none; }
.hot-cell:active { transform: translateY(1px); border-color: #f7d354; }
.hotbar.dun { background: linear-gradient(#2c2440, #1d1830); border-top-color: #5a4a7a; }
.hotbar.dun .hot-cell:not(.empty):not(.spell) { background: radial-gradient(#4a4566, #2b2840); border-color: #7a6a9a; }
.hot-emoji { font-size: calc(var(--hot) * 0.5); line-height: 1; pointer-events: none; }
.hot-emoji:empty { display: none; }
.hot-cell.spell { background: radial-gradient(#5a3a6e, #2e1f3d); border-color: #a07ac8; }
.hot-cell.spell .hot-n { font-size: 9px; color: #bfe0ff; }
.hot-cell.spell.none .hot-emoji { filter: grayscale(1) brightness(0.6); }
.hot-stars {
  position: absolute; right: 2px; top: 1px;
  font-size: 9px; line-height: 1; font-weight: 800;
  padding: 1px 2px; border-radius: 3px;
  color: #fff; text-shadow: 0 0 2px #000;
  pointer-events: none;
}
.hot-stars:empty { display: none; }
.hot-stars.r2 { background: #d9764a; }
.hot-stars.r3 { background: linear-gradient(90deg, #c42430, #7a5ad0); box-shadow: 0 0 4px #ffe066; }
.spell-rank { font-weight: 800; margin-right: 1px; }
.spell-rank.r2 { color: #d9764a; }
.spell-rank.r3 { color: #b0305c; text-shadow: 0 0 3px #ffe066; }
.spell-rumor { opacity: 0.75; border-style: dashed; }
.hot-cell.empty { background: #2a2219; border-color: #4a3828; border-style: dashed; }
.hot-cell.empty .item-icon, .hot-cell img:not([src]) { display: none; }
.hot-cell.none .item-icon { filter: grayscale(1) brightness(0.55); }
.hot-cell.worn { border-color: #c79a4a; }
.hot-no {
  position: absolute; left: 3px; top: 1px;
  font-size: 11px; font-weight: 800; font-style: italic; color: #e8dcc4;
  text-shadow: 1px 1px 0 #000; pointer-events: none; line-height: 1;
}
.hot-n {
  position: absolute; right: 3px; bottom: 2px;
  font-size: 12px; font-weight: 800; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; pointer-events: none; line-height: 1;
}

/* どうぐの まどの「📌 ショートカット」の ばんごう */
.hot-pick { display: grid; grid-template-columns: repeat(8, minmax(0, 40px)); gap: 4px; margin-top: 8px; }
.hot-pick-label { grid-column: 1 / -1; font-size: 12px; font-weight: 800; }
.hot-pick-btn {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 0;
  border: 2px solid #8a6a48; border-radius: 6px; background: #3b2e22;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.hot-pick-btn .item-icon { width: 24px; height: 24px; }
.hot-pick-btn .hot-emoji { font-size: 18px; }
.spell-pick { margin: 2px 0 10px; }
.hot-pick-btn.on { border-color: #f7d354; box-shadow: 0 0 0 2px #f7d354; background: #5a4a2a; }
.hot-pick-btn.empty { opacity: 0.55; cursor: default; }
.hot-pick-btn .hot-no { font-size: 10px; }
.hot-x { position: absolute; right: -5px; top: -6px; font-size: 10px; background: #b5482c; color: #fff; border-radius: 50%; width: 15px; height: 15px; line-height: 15px; text-align: center; }
.wood-frame .hot-pick { margin-top: 2px; justify-content: center; }

.msg.good { color: #9be36a; }
.msg.bad { color: #ff9a9a; }
.msg.warn { color: #ffd36a; }
.msg.info { color: #9fd0ff; }

/* ---------- 操作ボタン ---------- */

.controls {
  --pad: 58px;
  --gap: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  user-select: none;
  -webkit-user-select: none;
}

/* やじるし: ひだりて と みぎて に 2れつ × 3だん ずつ */
.dpad {
  display: grid;
  grid-template-columns: repeat(2, var(--pad));
  grid-template-rows: repeat(3, var(--pad));
  gap: var(--gap);
  flex-shrink: 0;
}
.dpad button {
  border: none;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text-light);
  font-size: 24px;
  font-weight: 700;
  touch-action: none;
  padding: 0;
}
.dpad button:active { background: var(--accent); }
.dpad .wait-btn { background: var(--panel-2); font-size: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.dpad .wait-btn span { font-size: 10px; margin-top: 2px; }

/* みぎての まんなか: しらべる(あかい まる) */
.main-btn {
  border-radius: 50% !important;
  background: #b5482c !important;
  box-shadow: 0 3px 0 #7d2f1c;
  font-size: 24px !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  touch-action: manipulation !important;
}
.main-btn span { font-size: 10px; margin-top: 2px; letter-spacing: -0.5px; }
.main-btn:active { background: #8f3721 !important; transform: translateY(2px); box-shadow: 0 1px 0 #7d2f1c; }
.main-btn.ready { background: #e0702a !important; animation: pulse 1s infinite; }

/* まんなか: どうぐ や まほう などを 1かいで おせる ボタン 8こ */
.tools {
  flex: 1;
  min-width: 0;
  max-width: 320px;
  height: calc(var(--pad) * 3 + var(--gap) * 2);
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: var(--gap);
}
.tools-a, .tools-b { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); min-height: 0; }
.act-btn {
  border: none;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text-light);
  font-size: 22px;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  line-height: 1;
}
.act-btn span { font-size: 11px; font-weight: 700; white-space: nowrap; letter-spacing: -0.5px; }
.act-btn:active { background: var(--accent-dark); }
.act-btn.on { background: var(--accent-dark); box-shadow: inset 0 0 0 2px var(--accent); }
.act-btn.ready { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { filter: brightness(1.3); } }

.key-hint { font-size: 12px; color: #5a7266; margin: 12px 0 0; line-height: 1.6; }
@media (hover: none) { .key-hint { display: none; } }

/* ---------- まど ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 16px;
  z-index: 10;
}
.modal-panel {
  position: relative;
  background: var(--paper);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.modal-title { margin: 0 32px 10px 0; font-size: 20px; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: transparent;
  font-size: 20px;
  color: var(--text-dark);
}
.dlg-line { margin: 4px 0; line-height: 1.7; }

.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.modal-buttons.left { justify-content: flex-start; margin-top: 6px; }

.primary-btn, .secondary-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
}
.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover:not(:disabled) { background: var(--accent-dark); }
.primary-btn.big { font-size: 20px; padding: 12px 34px; }
.secondary-btn { background: #d6cfbb; color: var(--text-dark); }
.secondary-btn:hover { background: #c8c0a9; }

.mini-btn {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  flex: none;
  white-space: nowrap;
}
.mini-btn.gray { background: #b5ae9a; }
.mini-btn.warn-btn { background: #d9764a; }

.muted { color: #6f6a5a; }
.small { font-size: 12px; }
.center { text-align: center; }
.notice {
  white-space: pre-line;
  background: #fff3c4;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 14px;
}
.warn-text { color: #b5482c; }
.sub-title { font-size: 15px; margin: 14px 0 6px; }

.stats-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--paper-2);
  border-radius: 6px;
}
.stat { display: flex; justify-content: space-between; gap: 6px; }
.stat-label { color: #5a5446; }

.equip-box { margin-top: 8px; display: grid; gap: 4px; }
.equip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 14px;
}
.equip-label {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--panel-2);
  border-radius: 4px;
  padding: 2px 6px;
}
.equip-name { flex: 1; }
/* ぶきの きれあじ(●○) */
.wear-meter { font-size: 11px; letter-spacing: 1px; color: #f2c94c; white-space: nowrap; }
.wear-meter.wear-2 { color: #e8913a; }
.wear-meter.wear-3 { color: #e05a4f; }

.item-icon { width: 28px; height: 28px; flex: none; image-rendering: pixelated; }
.item-list { display: grid; gap: 4px; }
.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 10px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: #fff;
  text-align: left;
  font-size: 15px;
  color: var(--text-dark);
}
.item-row.selected { border-color: var(--accent); background: #e9f8ef; }
.item-name { flex: 1; }
.item-count { font-weight: 700; color: #6f6a5a; }

/* もちものの ます目(Elona ふう の きわく) */
.wood-frame {
  margin: 10px 0 6px;
  padding: 4px 6px 7px;
  border-radius: 8px;
  background: linear-gradient(#8a5a32, #6b4223);
  border: 2px solid #3d2412;
  box-shadow: inset 0 0 0 2px #b07a45, 0 2px 0 rgba(0, 0, 0, 0.25);
}
.wood-title { color: #fbe9c6; font-weight: 800; font-size: 13px; padding: 1px 4px 4px; text-shadow: 0 1px 0 #3d2412; }
.inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 4px;
  border-radius: 4px;
  background: #2b2118;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.6);
}
.inv-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 2px solid #4a3a2a;
  border-radius: 4px;
  background: radial-gradient(#4b4036, #372d25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.inv-cell.empty { background: #30261e; border-color: #3a2e23; cursor: default; }
.inv-cell .item-icon { width: 62%; height: 62%; max-width: 48px; max-height: 48px; }
.inv-cell:not(.empty):hover { border-color: #b08a5a; }
.inv-cell.selected { border-color: #f7d354; box-shadow: 0 0 0 2px #f7d354, inset 0 0 10px rgba(247, 211, 84, 0.45); }
.inv-cell.picked { border-color: #6fd39b; background: radial-gradient(#3f6a4f, #2b4637); }
.inv-n, .inv-plus, .inv-badge {
  position: absolute;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
  pointer-events: none;
}
.inv-n { right: 3px; bottom: 3px; }
.inv-plus { left: 3px; top: 3px; color: #8fe3ff; }
.inv-badge { right: 2px; top: 2px; font-size: 11px; }
/* ぶきの たいきゅう(したの ぼう。へるほど みじかく、いろが かわる) */
.inv-wear { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 4px; border-radius: 2px; background: rgba(0, 0, 0, 0.6); overflow: hidden; pointer-events: none; }
.inv-wear > span { display: block; height: 100%; background: #6fd36f; }
.inv-wear.wear-1 > span { background: #f2c94c; }
.inv-wear.wear-2 > span { background: #e8913a; }
.inv-wear.wear-3 > span { background: #e05a4f; }

.detail-box {
  position: sticky;
  bottom: -18px;
  margin: 12px -18px -18px;
  padding: 12px 18px 16px;
  background: var(--paper-2);
  border-top: 2px solid var(--accent);
}
/* ひくい がめん(スマホ よこむき)では せつめいを ちいさく して ます目を かくしすぎない */
@media (max-height: 560px) {
  /* ひくい がめんでは 10れつ に して ます目を ひくく する */
  .inv-grid { grid-template-columns: repeat(10, 1fr); gap: 2px; padding: 3px; }
  .inv-n, .inv-plus { font-size: 10px; }
  .detail-box { padding: 8px 18px 10px; }
  .detail-box .detail-desc { font-size: 12px; }
  .detail-box .primary-btn, .detail-box .secondary-btn { padding: 6px 14px; }
}
.detail-name { font-weight: 800; margin: 0 0 4px; }
.detail-desc { font-size: 14px; margin: 0 0 6px; }

.tabs { display: flex; gap: 6px; margin: 8px 0; }
.tab {
  flex: 1;
  border: none;
  border-radius: 6px;
  padding: 8px;
  font-weight: 700;
  background: #d6cfbb;
  color: var(--text-dark);
}
.tab.on { background: var(--panel); color: var(--text-light); }

.shop-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 6px;
  padding: 7px 10px;
  margin-bottom: 4px;
}
.shop-row.picked { background: #fff3c4; }
.shop-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.quest-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.progress { font-size: 13px; font-weight: 700; }
.progress.done { color: var(--accent-dark); }
.ach-row .ach-icon { font-size: 22px; width: 32px; text-align: center; flex: none; }
.ach-row.locked { opacity: 0.6; }
.from { width: 100%; color: #6f6a5a; }

/* はたけ */
.farm-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.farm-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border: 2px solid #8a5a30; border-radius: 8px;
  background: #e8cfa4; color: var(--text-dark); font-size: 11px; min-height: 92px;
}
.farm-cell.wet { background: #c9a578; }
.farm-cell.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.farm-cell .item-icon { width: 36px; height: 36px; }
.farm-empty { font-size: 26px; line-height: 36px; color: #8a5a30; font-weight: 800; }
.farm-label { font-weight: 700; text-align: center; }
.farm-water { font-size: 10px; }
.mini-btn .item-icon { width: 20px; height: 20px; vertical-align: middle; margin-right: 2px; }

/* りょうり */
.recipe-need { display: flex; flex-wrap: wrap; gap: 4px; }
.recipe-chip { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; background: #e9f8ef; border-radius: 4px; padding: 0 4px 0 0; }
.recipe-chip.missing { background: #f6e0dc; color: #8a3a2c; }
.recipe-chip .item-icon { width: 20px; height: 20px; }

/* なかま */
.pet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.pet-portrait { width: 80px; height: 80px; image-rendering: pixelated; background: var(--paper-2); border-radius: 10px; flex: none; }
.pet-head-info { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.pet-name { font-size: 17px; }
.pet-bar { width: 100%; max-width: 180px; background: #d6cfbb; }
.hearts { font-size: 18px; letter-spacing: 1px; }
.pet-skill { margin-top: 8px; padding: 8px 10px; background: #fff; border-radius: 6px; font-size: 13px; }
.pet-skill b { display: block; margin-bottom: 2px; }

/* まちの ひと */
.folk-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.folk-head .item-icon { width: 56px; height: 56px; image-rendering: pixelated; background: var(--paper-2); border-radius: 10px; flex: none; }
.folk-info { display: flex; flex-direction: column; gap: 2px; }
.folk-req { background: #e6f4ff; border-radius: 6px; padding: 6px 10px; font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.folk-say { background: #fff; border-radius: 8px; padding: 10px 12px; font-size: 16px; font-weight: 700; line-height: 1.5; margin-bottom: 8px; }

/* つり */
.pond {
  position: relative;
  height: 130px;
  border-radius: 10px;
  background: linear-gradient(#5aa6e8, #2f6fcf);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.bobber { font-size: 30px; }
.bobber.wait { animation: bob 1.4s ease-in-out infinite; }
.bobber.bite { animation: shake 0.12s linear infinite; transform: translateY(10px); }
@keyframes bob { 50% { transform: translateY(5px); } }
@keyframes shake { 0% { transform: translate(-3px, 10px); } 50% { transform: translate(3px, 12px); } 100% { transform: translate(-3px, 10px); } }
.bite-mark {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 34px;
  animation: pulse 0.3s infinite;
}
.catch-icon { width: 72px; height: 72px; image-rendering: pixelated; }
.fish-status { font-weight: 700; min-height: 1.5em; }

.minimap {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  image-rendering: pixelated;
  border-radius: 6px;
}

.rule { margin-bottom: 12px; }
.rule h3 { margin: 0 0 4px; font-size: 16px; }
.rule p { margin: 0; font-size: 14px; line-height: 1.7; }

.hidden { display: none !important; }

@media (max-width: 480px) {
  body { padding: 8px 10px 20px; }
  h1 { font-size: 21px; }
  .status-bar { font-size: 12px; padding: 6px 10px; }
  .status-row { gap: 2px 9px; }
  .bar-bg { width: 40px; }
  .msg-log { font-size: 12px; padding: 5px 10px; }
  header { margin-bottom: 6px; flex-wrap: nowrap; }
  .header-buttons { gap: 4px; }
  .header-buttons .small-btn { padding: 5px 7px; font-size: 11px; white-space: nowrap; }
  .back-to-top { margin-bottom: 2px; }
  #game-canvas { object-fit: contain; }
  .controls { gap: 6px; margin-top: 8px; --pad: min(54px, 14vw, 8.6dvh); --gap: 4px; }
  /* せまい がめんでは まんなかの ボタンを 2れつ × 4だん に */
  .tools { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .tools-a, .tools-b { grid-template-columns: 1fr; grid-template-rows: repeat(5, 1fr); }
  .act-btn { flex-direction: row; gap: 1px; font-size: 16px; }
  .act-btn span { font-size: 10px; }
}

/* スマホ たてむき: スクロール しなくても ぜんぶの ボタンが みえるように、1がめんに おさめる。
   あまった たかさ だけ ゲームがめんを ちぢめる(Safari の アドレスバーぶんは 100dvh が ひいてくれる) */
@media (max-width: 480px) and (orientation: portrait) {
  body { padding: 4px 8px 6px; min-height: 0; }
  .container { height: calc(100vh - 10px); height: calc(100dvh - 10px); display: flex; flex-direction: column; position: relative; }
  /* ← TOP は タイトルと おなじ 1ぎょうに ならべる */
  .back-to-top { position: absolute; left: 0; top: 0; height: 28px; margin: 0; font-size: 12px; display: flex; align-items: center; white-space: nowrap; }
  header { margin-bottom: 4px; flex-wrap: nowrap; gap: 6px; min-height: 28px; padding-left: 40px; }
  .header-buttons { gap: 3px; }
  .header-buttons .small-btn { padding: 5px 5px; }
  h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .header-buttons { flex-shrink: 0; }
  .header-buttons .lbl { display: none; }
  .status-bar { padding: 4px 9px; }
  .status-row + .status-row { margin-top: 1px; }
  .play, .board-wrap { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #game-canvas { flex: 0 1 auto; min-height: 0; height: auto; }
  .msg-log { flex: none; line-height: 1.35; height: calc(1.35em * 3 + 10px); }
  .hotbar { flex: none; }
  .controls { flex: none; }
}

/* ランキング(オンライン) */
.rank-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  margin: 4px 0;
}
.rank-row.me { box-shadow: inset 0 0 0 2px var(--accent); }
.rank-no { width: 28px; text-align: center; }
.rank-name { flex: 1; }
.rank-val { white-space: nowrap; }
.rank-preview { font-size: 20px; font-weight: 800; margin: 8px 0; }

/* ---------- ずかん ---------- */

.book-stamp {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #fff6d8; border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 700;
}
.book-tabs { flex-wrap: wrap; }
.book-tabs .tab { flex: 1 1 auto; padding: 6px 4px; font-size: 13px; }
.book-tabs .tab.done { box-shadow: inset 0 0 0 2px #f7dc4f; }
.book-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 6px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 4px; }
.book-cell {
  position: relative; border: none; border-radius: 8px; background: #efe6cf; padding: 6px 0 4px;
  display: flex; justify-content: center; cursor: pointer;
}
.book-cell .item-icon { width: 32px; height: 32px; }
.book-cell.unknown { background: #d9d2c0; }
.book-cell.unknown .item-icon { filter: brightness(0) opacity(0.35); }
.book-cell.selected { box-shadow: inset 0 0 0 2px var(--accent-dark); }
.book-no { position: absolute; left: 3px; top: 1px; font-size: 9px; color: #8a7f68; }
.book-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }

/* ---------- スマホ・タブレット よこむき: ひだりに やじるし(ひだり)、まんなかに がめん、みぎに やじるし(みぎ) ----------
   タブレット(iPad など)の よこむきも、たてに つむと ボタンが がめんの したに はみでるので この ならびに する */
@media (orientation: landscape) and (max-height: 560px), (orientation: landscape) and (any-pointer: coarse) and (max-height: 1100px) {
  body { padding: 4px 8px; }
  .container { max-width: none; }
  /* TOP と あそびかた・はじめから は ひだりうえの すみに ちいさく */
  .back-to-top { position: fixed; top: 6px; left: 10px; margin: 0; z-index: 2; }
  header { position: fixed; top: 4px; right: 10px; margin: 0; z-index: 2; }
  header h1 { display: none; }
  .small-btn { padding: 4px 8px; font-size: 11px; }
  .play {
    display: grid;
    /* がめんの よこはばは たかさから きめる(15×11 マス) */
    grid-template-columns: 1fr minmax(0, calc((100dvh - 108px - var(--hot-h)) * 15 / 11)) 1fr;
    grid-template-areas: "toolsa status toolsb" "toolsa board toolsb" "padl board padr";
    grid-template-rows: auto 1fr auto;
    column-gap: 10px;
    height: calc(100vh - 8px);
    height: calc(100dvh - 8px);
  }
  :root { --hot: min(40px, 9.5vh); }
  .controls, .tools { display: contents; --pad: min(58px, 14vh); --gap: 5px; }
  .dpad-l { grid-area: padl; align-self: end; justify-self: center; margin-bottom: 6px; }
  .dpad-r { grid-area: padr; align-self: end; justify-self: center; margin-bottom: 6px; }
  .tools-a, .tools-b {
    align-self: end; justify-self: center; width: min(100%, calc(var(--pad) * 2 + 5px));
    grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; margin-bottom: 8px;
  }
  .tools-a { grid-area: toolsa; }
  .tools-b { grid-area: toolsb; }
  .tools-a .act-btn, .tools-b .act-btn { height: calc(var(--pad) * 0.85); }
  .status-bar { grid-area: status; font-size: 11px; padding: 4px 8px; align-self: end; }
  .status-row { gap: 1px 8px; }
  .st-place { font-size: 12px; }
  .bar-bg { width: 34px; }
  .board-wrap { grid-area: board; align-self: start; }
  .status-bar { grid-row: 1; }
  .msg-log { font-size: 11px; padding: 3px 8px; }
  .key-hint { display: none; }
}
/* タブレットの よこむきは がめんが ひろいので、ボタンを すこし おおきく */
@media (orientation: landscape) and (min-height: 561px) and (any-pointer: coarse) and (max-height: 1100px) {
  :root { --hot: min(60px, 6.5vh); }
  .controls, .tools { --pad: min(74px, 9.5vh); --gap: 6px; }
  .act-btn { font-size: 26px; }
  .act-btn span { font-size: 12px; }
}

/* ボスを たおした ときの「ダンジョン クリア!」の まど */
.clear-box { text-align: center; }
.clear-pic {
  position: relative; display: inline-block; padding: 10px; margin: 2px 0 6px;
  background: radial-gradient(circle, #fff3c4 0%, #ffe08a 55%, #f5c24a 100%);
  border-radius: 50%; border: 3px solid #e4a43a; animation: clearPop 0.45s ease-out;
}
.clear-pic .item-icon { width: 88px; height: 88px; display: block; }
.clear-stamp {
  position: absolute; right: -18px; bottom: 4px; padding: 2px 8px;
  background: #e43b44; color: #fff; font-weight: 900; font-size: 16px;
  border: 3px solid #fff; border-radius: 8px; transform: rotate(-14deg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); animation: clearStamp 0.4s 0.35s ease-out backwards;
}
.clear-name { font-size: 22px; font-weight: 900; margin: 4px 0 0; color: #733e39; }
.clear-dun { margin: 2px 0 6px; font-weight: 700; color: #6f6a5a; }
.clear-talk { margin: 4px 0 2px; font-weight: 700; color: #3a4466; line-height: 1.6; }
.clear-promise { margin: 0 0 8px; font-weight: 900; color: #3e8948; }
.clear-first { margin: 0 0 8px; font-weight: 900; color: #c47a00; font-size: 17px; }
.clear-rewards { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 6px 0 10px; }
.clear-reward {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
  background: var(--paper-2); border-radius: 999px; font-weight: 700; font-size: 15px;
}
.clear-reward .item-icon { width: 24px; height: 24px; }
@keyframes clearPop { 0% { transform: scale(0.3); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes clearStamp { 0% { transform: rotate(-14deg) scale(2.4); opacity: 0; } 100% { transform: rotate(-14deg) scale(1); opacity: 1; } }

/* おとの せってい */
.sound-label { margin: 10px 0 4px; font-weight: bold; }
.sound-row { display: flex; gap: 6px; flex-wrap: wrap; }
.sound-row button { flex: 1 1 0; min-width: 64px; padding: 8px 4px; }
.key-head { grid-column: 1 / -1; margin: 6px 0 0; }
.modal-buttons.left .small { align-self: center; }

/* ---------- ぶきの ごうせい ---------- */
.fuse-mat { align-items: flex-start; }
.fuse-seals { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
.modal.fuse-busy .modal-close { visibility: hidden; }
.fuse-stage {
  position: relative;
  height: 200px;
  margin: 4px 0 10px;
  border-radius: 10px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 55%, #3a4466 0%, #262b44 55%, #181425 100%);
  box-shadow: inset 0 0 0 3px #5a3a22, inset 0 0 0 5px #8a5a32;
}
.fuse-glow {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%; background: radial-gradient(circle, #fff 0%, #fee761 35%, rgba(254, 174, 52, 0) 70%);
  opacity: 0; transform: scale(0.3);
}
.fuse-orbit { position: absolute; inset: 0; }
.fuse-wpn {
  position: absolute; top: 50%; width: 64px; height: 64px; margin-top: -32px;
  image-rendering: pixelated; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.45));
}
.fuse-a { left: 12%; }
.fuse-b { right: 12%; }
.fuse-seal {
  position: absolute; right: 12%; top: 18%; width: 64px; text-align: center; font-size: 26px;
  filter: drop-shadow(0 0 6px #fee761);
}
.fuse-word {
  position: absolute; left: 0; right: 0; bottom: 10px; text-align: center;
  font-weight: bold; font-size: 20px; color: #fff; text-shadow: 0 2px 0 #181425, 0 0 8px #3a4466;
}
.fuse-stage.go:not(.win):not(.lose) .fuse-word::after { content: ""; animation: fuse-dots 0.9s steps(4) infinite; }
.fuse-spark {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px;
  background: #fee761; box-shadow: 0 0 6px #feae34; opacity: 0;
  transform: rotate(var(--ang)) translateX(0);
}
.fuse-smoke { position: absolute; left: 50%; top: 50%; }
.fuse-smoke i {
  position: absolute; width: 46px; height: 46px; margin: -23px; border-radius: 50%;
  background: #c0cbdc; opacity: 0; transform: rotate(var(--ang)) translateX(0) scale(0.3);
}
.fuse-bar { height: 10px; border-radius: 5px; background: #d9c7a5; overflow: hidden; }
.fuse-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #feae34, #fee761); animation: fuse-bar 2.4s linear forwards; }
.fuse-result { margin-top: 10px; }

/* 1) ふたつの ぶきが まんなかへ */
.fuse-stage.go .fuse-a { animation: fuse-in-a 0.9s ease-in forwards; }
.fuse-stage.go .fuse-b { animation: fuse-in-b 0.9s ease-in forwards; }
.fuse-stage.go .fuse-seal { animation: fuse-seal-in 0.9s ease-in forwards; }
/* 2) ぐるぐる まわって ひかる */
.fuse-stage.spin .fuse-orbit { animation: fuse-orbit 0.45s linear infinite; }
.fuse-stage.spin .fuse-wpn { animation: none; top: 50%; left: 50%; right: auto; margin-left: -32px; }
.fuse-stage.spin .fuse-a { transform: translateX(-18px) rotate(-20deg); }
.fuse-stage.spin .fuse-b { transform: translateX(18px) rotate(20deg) scale(0.8); }
.fuse-stage.spin .fuse-glow { animation: fuse-glow 1.45s ease-in forwards; }
.fuse-stage.spin .fuse-spark { animation: fuse-spark 0.6s ease-out infinite; }
.fuse-stage.spin .fuse-seal { opacity: 0; }
/* 3a) せいこう: ひとつに なって、しるしが ぽんっ */
.fuse-stage.win { animation: fuse-flash 0.5s ease-out; }
.fuse-stage.win .fuse-wpn { top: 50%; left: 50%; right: auto; margin-left: -32px; }
.fuse-stage.win .fuse-b { display: none; }
.fuse-stage.win .fuse-a { animation: fuse-pop 0.6s cubic-bezier(.3, 1.6, .5, 1) forwards; filter: drop-shadow(0 0 10px #fee761); }
.fuse-stage.win .fuse-glow { opacity: 0.9; transform: scale(3.2); transition: opacity 0.6s; }
.fuse-stage.win .fuse-seal { right: auto; left: 50%; margin-left: -32px; top: 6%; animation: fuse-seal-pop 0.7s 0.2s cubic-bezier(.3, 1.6, .5, 1) both; }
.fuse-stage.win .fuse-word { color: #fee761; animation: fuse-pop 0.5s cubic-bezier(.3, 1.6, .5, 1); }
/* 3b) しっぱい: けむりが でて、ぶきが がたがた */
.fuse-stage.lose { animation: fuse-shake 0.4s linear 2; }
.fuse-stage.lose .fuse-wpn { top: 50%; left: 50%; right: auto; margin-left: -32px; }
.fuse-stage.lose .fuse-b { display: none; }
.fuse-stage.lose .fuse-a { filter: grayscale(0.7) brightness(0.7); }
.fuse-stage.lose .fuse-smoke i { animation: fuse-smoke 1s ease-out forwards; }
.fuse-stage.lose .fuse-glow { opacity: 0; }
.fuse-stage.lose .fuse-seal { opacity: 0; }
.fuse-stage.lose.lost .fuse-seal { right: auto; left: 50%; margin-left: -32px; top: 22%; animation: fuse-seal-lost 1.1s 0.3s ease-in both; }
.fuse-stage.lose .fuse-word { color: #c0cbdc; }

@keyframes fuse-in-a { to { left: 50%; margin-left: -50px; } }
@keyframes fuse-in-b { to { right: 50%; margin-right: -50px; transform: scale(0.85); } }
@keyframes fuse-seal-in { to { right: 50%; margin-right: -50px; top: 30%; opacity: 0.4; } }
@keyframes fuse-orbit { to { transform: rotate(360deg); } }
@keyframes fuse-glow { from { opacity: 0.2; transform: scale(0.4); } to { opacity: 1; transform: scale(3.6); } }
@keyframes fuse-spark { 0% { opacity: 1; transform: rotate(var(--ang)) translateX(10px); } 100% { opacity: 0; transform: rotate(var(--ang)) translateX(90px); } }
@keyframes fuse-flash { 0% { box-shadow: inset 0 0 0 200px #fff; } 100% { box-shadow: inset 0 0 0 3px #5a3a22, inset 0 0 0 5px #8a5a32; } }
@keyframes fuse-pop { 0% { transform: scale(0.4); } 100% { transform: scale(1.25); } }
@keyframes fuse-seal-pop { 0% { opacity: 0; transform: translateY(40px) scale(0.3); } 100% { opacity: 1; transform: translateY(0) scale(1.4); } }
@keyframes fuse-seal-lost { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(70px) rotate(120deg) scale(0.5); filter: grayscale(1); } }
@keyframes fuse-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes fuse-smoke { 0% { opacity: 0.9; transform: rotate(var(--ang)) translateX(0) scale(0.4); } 100% { opacity: 0; transform: rotate(var(--ang)) translateX(60px) scale(1.6); } }
@keyframes fuse-bar { to { width: 100%; } }
@keyframes fuse-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
@media (prefers-reduced-motion: reduce) {
  .fuse-stage.spin .fuse-orbit, .fuse-stage.spin .fuse-spark { animation-duration: 2s; }
}
.spell-btns { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
