@import url("variables.css");

/* ================================================
   基本
   ================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--c-bg); }
canvas { display: block; }
body { font-family: var(--font-ui); color: var(--c-text); user-select: none; }
.hidden { display: none !important; }

kbd {
    background: #1b2838;
    border: 1px solid #2f4760;
    border-radius: 3px;
    padding: 0 5px;
    color: var(--c-text);
    font-size: 11px;
}

#loading {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    font: 14px var(--font-ui); color: var(--c-accent); background: var(--c-bg);
}

.panel {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 6px;
    padding: 9px 11px;
}

/* ================================================
   HUD
   ================================================ */
#hud {
    position: fixed; top: 12px; left: 12px;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
    font-size: 12px; line-height: 1.5;
}

.status { width: 252px; }
.status .name {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 7px;
}
.status .lv { font-size: 13px; color: var(--c-text-dim); }
.status .lv b { color: var(--c-value); font-size: 17px; }
.status .job { color: var(--c-accent); font-size: 11px; }

.bar {
    position: relative;
    height: 15px;
    border-radius: 3px;
    margin-bottom: 4px;
    overflow: hidden;
}
.bar:last-child { margin-bottom: 0; }
.bar i {
    display: block; height: 100%; width: 100%;
    transform-origin: left center;
    transition: transform 0.18s ease-out;
}
.bar span {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: flex-end;
    padding-right: 6px;
    font-size: 10px;
    text-shadow: 0 1px 2px #000;
}
.bar.hp  { background: var(--c-hp-bg); }
.bar.hp  i { background: var(--c-hp); }
.bar.mp  { background: var(--c-mp-bg); height: 11px; }
.bar.mp  i { background: var(--c-mp); }
.bar.exp { background: var(--c-exp-bg); height: 7px; }
.bar.exp i { background: var(--c-exp); }
.bar.exp span { font-size: 9px; }

.stats { width: 252px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; }
.stats .st { font-size: 10px; color: var(--c-text-dim); }
.stats .st b { display: block; font-size: 14px; color: var(--c-text); font-weight: normal; }

.debug { width: 252px; display: flex; gap: 12px; font-size: 11px; color: var(--c-text-dim); }
.debug b { color: var(--c-value); font-weight: normal; }

/* ================================================
   ログ
   ================================================ */
#log {
    position: fixed; bottom: 70px; left: 12px;
    width: 340px;
    display: flex; flex-direction: column-reverse; gap: 3px;
    pointer-events: none;
    font-size: 12px;
}
#log div {
    background: rgba(8, 14, 22, 0.6);
    border-left: 2px solid var(--c-accent);
    padding: 3px 8px;
    animation: logIn 0.2s ease-out;
}
#log div.good { border-left-color: var(--c-exp); color: var(--c-exp); }
#log div.bad  { border-left-color: var(--c-hp); color: #ffb0ab; }
@keyframes logIn { from { opacity: 0; transform: translateX(-8px); } }

/* ================================================
   ダメージポップアップ
   ================================================ */
#popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#popups .pop {
    position: absolute;
    font-size: 17px;
    font-weight: bold;
    color: var(--c-damage);
    text-shadow: 0 2px 4px #000, 0 0 8px #000;
    transform: translate(-50%, -50%);
    animation: popUp 0.85s ease-out forwards;
}
#popups .pop.crit  { color: var(--c-crit); font-size: 24px; }
#popups .pop.taken { color: var(--c-player-dmg); }
#popups .pop.exp   { color: var(--c-exp); font-size: 14px; }
@keyframes popUp {
    0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
    18%  { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -165%) scale(1); }
}

/* ================================================
   オーバーレイ（レベルアップ / 死亡）
   ================================================ */
#levelup, #dead {
    position: fixed; inset: 0; z-index: 50;
    display: flex; align-items: center; justify-content: center;
    background: rgba(4, 8, 14, 0.55);
    backdrop-filter: blur(2px);
}
#levelup .box, #dead .box {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 24px 28px;
    text-align: center;
    min-width: 380px;
    animation: boxIn 0.25s ease-out;
}
@keyframes boxIn { from { opacity: 0; transform: translateY(12px); } }

#levelup h2, #dead h2 {
    font-size: 19px; font-weight: normal; letter-spacing: 3px;
    color: var(--c-accent); margin-bottom: 10px;
}
#dead h2 { color: var(--c-hp); }
#levelup p, #dead p { font-size: 12px; color: var(--c-text-dim); margin-bottom: 16px; }
#levelup b { color: var(--c-value); }
#levelup .hint { margin: 14px 0 0; font-size: 11px; }

.alloc { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.alloc button {
    background: #16222f;
    border: 1px solid #2f4760;
    border-radius: 5px;
    padding: 10px 4px;
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.alloc button:hover { background: #1f3346; border-color: var(--c-accent); }
.alloc button b { display: block; font-size: 16px; color: var(--c-value); font-weight: normal; margin-top: 3px; }
.alloc button small { display: block; font-size: 9px; color: var(--c-text-dim); margin-top: 3px; }

/* ================================================
   操作説明
   ================================================ */
#help {
    position: fixed; bottom: 12px; left: 12px;
    font-size: 11px; line-height: 1.8;
    color: var(--c-text-dim);
    background: var(--c-panel);
    border: 1px solid rgba(120, 180, 255, 0.18);
    border-radius: 6px;
    padding: 8px 11px;
    pointer-events: none;
}

/* ================================================
   精神負荷バー
   ================================================ */
.bar.psi { background: #2a1a4a; height: 9px; }
.bar.psi i { background: var(--c-psi); }
.bar.psi span { font-size: 9px; }

/* ================================================
   スキルバー
   ================================================ */
#skillbar {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    pointer-events: none;
}
#skillbar .slot {
    position: relative;
    width: 86px;
    padding: 6px 7px 7px;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 5px;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.4;
}
#skillbar .slot.magic { border-color: rgba(92, 225, 255, 0.45); }
#skillbar .slot.psi   { border-color: rgba(176, 143, 255, 0.5); }
#skillbar .slot.art   { border-color: rgba(255, 217, 143, 0.4); }
#skillbar .slot.disabled { opacity: 0.4; }

#skillbar .key {
    position: absolute; top: 4px; right: 6px;
    font-size: 10px; color: var(--c-text-dim);
}
#skillbar .nm   { display: block; color: var(--c-text); }
#skillbar .cost { display: block; font-size: 9px; color: var(--c-text-dim); }
#skillbar .cd {
    position: absolute; inset: 0;
    background: rgba(4, 8, 14, 0.72);
    transform-origin: top center;
    transform: scaleY(0);
}

/* ================================================
   メニュー（職業 / スキル）
   ================================================ */
#menu {
    position: fixed; inset: 0; z-index: 60;
    display: flex; align-items: center; justify-content: center;
    background: rgba(4, 8, 14, 0.6);
    backdrop-filter: blur(2px);
}
#menu .window {
    width: min(860px, 92vw);
    max-height: 86vh;
    display: flex; flex-direction: column;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    animation: boxIn 0.2s ease-out;
}
#menu .mhead {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
}
#menu-tabs { display: flex; gap: 6px; }
#menu-tabs button {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 5px 16px;
    color: var(--c-text-dim);
    font-family: var(--font-ui);
    font-size: 12px;
    cursor: pointer;
}
#menu-tabs button.on { color: var(--c-accent); border-color: var(--c-border); background: #16222f; }
#menu .close { font-size: 11px; color: var(--c-text-dim); }

#menu-body {
    overflow-y: auto;
    padding: 14px;
    font-size: 12px;
    line-height: 1.6;
}
#menu-body .lead { color: var(--c-text-dim); margin-bottom: 12px; }
#menu-body .lead b { color: var(--c-accent); }
#menu-body .dim { color: var(--c-text-dim); }
#menu-body h3 {
    font-size: 12px; font-weight: normal; color: var(--c-accent);
    margin: 16px 0 8px; padding-bottom: 4px;
    border-bottom: 1px solid rgba(120, 180, 255, 0.15);
}
#menu-body h3 small { color: var(--c-text-dim); margin-left: 8px; }

/* 職業カード */
.job {
    border: 1px solid rgba(120, 180, 255, 0.14);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 9px;
    background: rgba(12, 20, 30, 0.5);
}
.job.current { border-color: var(--c-accent); background: rgba(22, 44, 60, 0.5); }
.job.locked  { opacity: 0.55; }
.jhead { display: flex; align-items: center; gap: 10px; }
.jname { font-size: 14px; color: var(--c-text); }
.jlv   { font-size: 11px; color: var(--c-text-dim); }
.jlv b { color: var(--c-value); font-weight: normal; }
.jlv i { color: var(--c-accent); font-style: normal; }
.jhead button {
    margin-left: auto;
    background: #1f3346; border: 1px solid #2f4760; border-radius: 4px;
    padding: 4px 14px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 11px; cursor: pointer;
}
.jhead button:hover { border-color: var(--c-accent); }
.jhead .tag {
    margin-left: auto; font-size: 10px; color: var(--c-accent);
    border: 1px solid var(--c-border); border-radius: 3px; padding: 2px 8px;
}
.jhead .tag.lock { color: var(--c-text-dim); }
.jdesc { color: var(--c-text-dim); margin: 5px 0 7px; font-size: 11px; }

.jbar { height: 4px; background: #16222f; border-radius: 2px; overflow: hidden; margin-bottom: 7px; }
.jbar i { display: block; height: 100%; background: var(--c-exp); transform-origin: left center; }

.jmods { font-size: 11px; margin-bottom: 6px; }
.jmods .up   { color: var(--c-exp); }
.jmods .down { color: #ff9b94; }

.jskills { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.jskills .sk {
    font-size: 10px; padding: 2px 8px; border-radius: 3px;
    background: #16222f; border: 1px solid #2f4760; color: var(--c-text);
}
.jskills .sk small { color: var(--c-text-dim); margin-left: 5px; }
.jskills .sk.locked { opacity: 0.45; }

.jmastery { list-style: none; font-size: 11px; color: var(--c-text-dim); }
.jmastery li { padding: 1px 0; }
.jmastery li.got { color: var(--c-text); }
.jmastery li b { color: var(--c-value); font-weight: normal; }
.jmastery li i { color: var(--c-exp); font-style: normal; font-size: 10px; }

/* スキルカード */
.skills { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.skill {
    border: 1px solid rgba(120, 180, 255, 0.14);
    border-left-width: 3px;
    border-radius: 5px;
    padding: 8px 10px;
    background: rgba(12, 20, 30, 0.5);
}
.skill.magic { border-left-color: var(--c-accent); }
.skill.psi   { border-left-color: var(--c-psi); }
.skill.art   { border-left-color: var(--c-value); }
.shead { display: flex; justify-content: space-between; align-items: baseline; }
.shead span { font-size: 10px; color: var(--c-text-dim); }
.skill p { font-size: 11px; color: var(--c-text-dim); margin-top: 3px; }

.mlist { list-style: none; font-size: 11px; }
.mlist li { padding: 2px 0; color: var(--c-text); }
.mlist li b { color: var(--c-value); font-weight: normal; }

#popups .pop.heal { color: var(--c-heal); }

/* ================================================
   持ち物・装備
   ================================================ */
.stats .st b.buffed { color: var(--c-exp); }

.eqgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 6px;
}
.eq {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    border: 1px solid rgba(120, 180, 255, 0.14);
    border-radius: 5px;
    padding: 6px 9px;
    background: rgba(12, 20, 30, 0.5);
}
.eq.empty { opacity: 0.5; }
.eq .eslot {
    font-size: 10px; color: var(--c-text-dim);
    min-width: 36px;
}
.eq .ename { font-size: 12px; }
.eq .estats { flex-basis: 100%; }
.eq button, .item button {
    margin-left: auto;
    background: #1f3346; border: 1px solid #2f4760; border-radius: 4px;
    padding: 2px 10px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 10px; cursor: pointer;
}
.eq button:hover, .item button:hover { border-color: var(--c-accent); }
.item button.sell { background: #30202a; }


/* アカウント（セーブの引き継ぎ） */
.acc { max-width: 560px; }
.acc-form {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px;
    margin: 6px 0;
}
.acc-form label {
    display: flex; flex-direction: column; gap: 3px;
    font-size: 10px; color: var(--c-text-dim);
}
.acc-form input {
    width: 200px;
    background: rgba(4, 8, 14, 0.6);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--c-text);
    font-family: var(--font-ui); font-size: 12px;
}
.acc-form input:focus { outline: none; border-color: var(--c-accent); }
.acc-form button {
    background: #1f3346; border: 1px solid #2f4760; border-radius: 4px;
    padding: 6px 16px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 11px; cursor: pointer;
}
.acc-form button:hover:not(:disabled) { border-color: var(--c-accent); }
.acc-form button:disabled { opacity: 0.5; cursor: default; }
.acc-form button.sell { background: #30202a; }
.acc-msg { min-height: 16px; font-size: 11px; color: var(--c-text-dim); }
.acc-msg.bad { color: var(--c-hp); }

/* スマホでは1列に積む（入力欄が見切れないように） */
body.is-touch .acc-form { flex-direction: column; align-items: stretch; }
body.is-touch .acc-form input { width: 100%; }
body.is-touch .acc-form button { padding: 12px 16px; font-size: 13px; }

/* 設定タブ（音量など） */
.cfg-row {
    display: flex; align-items: center; gap: 12px;
    margin: 8px 0; font-size: 12px;
}
.cfg-row label { color: var(--c-text-dim); min-width: 92px; }
.cfg-row input[type="range"] { width: 220px; accent-color: var(--c-accent); }
.cfg-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--c-accent); }
.cfg-row b { color: var(--c-value); min-width: 28px; }

/* スマホでは指で触れる大きさにする */
body.is-touch .cfg-row { gap: 14px; font-size: 13px; }
body.is-touch .cfg-row input[type="range"] { flex: 1; height: 32px; }
body.is-touch .cfg-row input[type="checkbox"] { width: 24px; height: 24px; }

.items { display: flex; flex-direction: column; gap: 4px; }
.item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 8px;
    border: 1px solid rgba(120, 180, 255, 0.1);
    border-radius: 5px;
    padding: 6px 9px;
    background: rgba(12, 20, 30, 0.45);
}
.item .iname  { font-size: 12px; }
.item .ikind  { font-size: 10px; color: var(--c-text-dim); grid-row: 1; grid-column: 2; }
.item .istats { grid-column: 1 / -1; }
.item .ibtn   { grid-column: 1 / -1; display: flex; gap: 5px; justify-content: flex-end; }
.item .ibtn button { margin-left: 0; }

.stat {
    display: inline-block;
    font-size: 10px;
    color: var(--c-text-dim);
    margin-right: 9px;
}

/* ================================================
   クエスト追跡（画面右上）
   ================================================ */
#tracker {
    position: fixed;
    top: 12px; right: 12px;
    width: 250px;
    display: flex; flex-direction: column; gap: 5px;
    pointer-events: none;
    font-size: 11px;
}
#tracker .q {
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-left: 2px solid var(--c-value);
    border-radius: 5px;
    padding: 6px 9px;
}
#tracker .q.done { border-left-color: var(--c-exp); }
#tracker .qt { display: block; color: var(--c-text); }
#tracker .qo { color: var(--c-text-dim); }
#tracker .to { color: var(--c-exp); margin-left: 5px; }

/* ================================================
   会話ウィンドウ
   ================================================ */
#dialog {
    position: fixed; inset: auto 0 0 0; z-index: 55;
    display: flex; justify-content: center;
    padding: 0 16px 90px;
    pointer-events: none;
}
#dialog .box {
    width: min(720px, 100%);
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 14px 18px 16px;
    pointer-events: auto;
    animation: boxIn 0.16s ease-out;
}
#dlg-name {
    font-size: 12px; color: var(--c-accent);
    border-bottom: 1px solid rgba(120, 180, 255, 0.18);
    padding-bottom: 6px; margin-bottom: 9px;
}
#dlg-text { font-size: 13px; line-height: 1.8; color: var(--c-text); }
#dlg-extra {
    margin-top: 9px; padding: 8px 10px;
    background: rgba(22, 34, 47, 0.7);
    border-left: 2px solid var(--c-value);
    border-radius: 4px;
    font-size: 11px; color: var(--c-text-dim); line-height: 1.7;
}
#dlg-extra b { color: var(--c-value); font-weight: normal; }
#dlg-choices { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
#dlg-choices button {
    background: #1f3346; border: 1px solid #2f4760; border-radius: 4px;
    padding: 6px 16px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 12px; cursor: pointer;
}
#dlg-choices button:hover { border-color: var(--c-accent); background: #27425a; }
#dlg-choices .num { color: var(--c-text-dim); margin-right: 7px; font-size: 10px; }

/* ================================================
   クエストタブ
   ================================================ */
.quests { display: flex; flex-direction: column; gap: 7px; }
.quest {
    border: 1px solid rgba(120, 180, 255, 0.14);
    border-left: 3px solid var(--c-value);
    border-radius: 5px;
    padding: 8px 11px;
    background: rgba(12, 20, 30, 0.5);
}
.quest.done { border-left-color: var(--c-exp); }
.qhead { display: flex; justify-content: space-between; align-items: baseline; }
.qhead b { font-size: 13px; font-weight: normal; }
.qkind { font-size: 10px; color: var(--c-text-dim); }
.quest p { font-size: 11px; color: var(--c-text-dim); margin: 4px 0 6px; }
.qobj { font-size: 11px; color: var(--c-text); }
.qobj i { color: var(--c-exp); font-style: normal; }

.memos { display: flex; flex-direction: column; gap: 7px; }
.memo {
    border-left: 2px solid var(--c-value);
    background: rgba(22, 34, 47, 0.55);
    border-radius: 4px;
    padding: 8px 11px;
}
.memo b { font-size: 11px; color: var(--c-value); font-weight: normal; }
.memo p { font-size: 11px; color: var(--c-text-dim); line-height: 1.8; margin-top: 4px; }

/* ================================================
   保存ボタン
   ================================================ */
#menu .close { display: flex; align-items: center; gap: 10px; }
#save-status { font-size: 10px; color: var(--c-text-dim); font-weight: normal; }
#btn-save {
    background: #1f3346; border: 1px solid #2f4760; border-radius: 4px;
    padding: 3px 12px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 11px; cursor: pointer;
}
#btn-save:hover:not(:disabled) { border-color: var(--c-accent); }
#btn-save:disabled { opacity: 0.5; cursor: default; }

/* ================================================
   エリア切り替え
   ================================================ */
#fade {
    position: fixed; inset: 0; z-index: 90;
    background: var(--c-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#fade.on { opacity: 1; }

#area-banner {
    position: fixed;
    top: 24%; left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    z-index: 40;
    animation: areaIn 0.5s ease-out;
}
#area-banner b {
    display: block;
    font-size: 26px;
    font-weight: normal;
    letter-spacing: 6px;
    color: var(--c-text);
    text-shadow: 0 2px 12px #000, 0 0 30px #000;
}
#area-banner span {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--c-text-dim);
    text-shadow: 0 1px 6px #000;
}
@keyframes areaIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
}
#area-banner.out { opacity: 0; transition: opacity 0.8s ease; }

.debug #hud-area { color: var(--c-accent); }

/* ================================================
   スマホ対応
   ================================================ */
html, body { height: 100dvh; }

body.is-touch {
    touch-action: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}

/* ノッチを避ける */
body.is-touch #hud     { top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); }
body.is-touch #tracker { top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
body.is-touch #help    { display: none; }
body.is-touch #log     { bottom: calc(110px + env(safe-area-inset-bottom)); }

/* 指で押せる大きさにする */
body.is-touch #dlg-choices button,
body.is-touch .alloc button { min-height: 52px; font-size: 14px; }
body.is-touch #menu-tabs button { padding: 10px 18px; font-size: 14px; }
body.is-touch .item button, body.is-touch .eq button, body.is-touch .jhead button { min-height: 38px; padding: 6px 16px; }

/* ------------- 操作レイヤー ------------- */
#touch { position: fixed; inset: 0; z-index: 30; }

#touch-surface {
    position: absolute; inset: 0;
    touch-action: none;
}

#stick {
    position: absolute;
    width: 132px; height: 132px;
    margin: -66px 0 0 -66px;
    border: 2px solid rgba(207, 232, 255, 0.35);
    border-radius: 50%;
    background: rgba(8, 14, 22, 0.3);
    opacity: 0;
    transition: opacity 0.12s;
    pointer-events: none;
}
#stick.on { opacity: 1; }
#stick.dash { border-color: var(--c-value); }

#stick-knob {
    position: absolute;
    left: 50%; top: 50%;
    width: 54px; height: 54px;
    margin: -27px 0 0 -27px;
    border-radius: 50%;
    background: rgba(207, 232, 255, 0.55);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
#stick.dash #stick-knob { background: var(--c-value); }

#btn-attack {
    position: absolute;
    right: calc(26px + env(safe-area-inset-right));
    bottom: calc(26px + env(safe-area-inset-bottom));
    width: 108px; height: 108px;
    border-radius: 50%;
    border: 2px solid rgba(255, 217, 143, 0.5);
    background: rgba(31, 51, 70, 0.6);
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 15px;
    touch-action: none;
}
#btn-attack.on { background: rgba(255, 217, 143, 0.35); transform: scale(0.94); }

/* ------------- 縦持ちの案内 ------------- */
#rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
    #rotate-hint {
        position: fixed; inset: 0; z-index: 120;
        display: flex; flex-direction: column;
        align-items: center; justify-content: center; gap: 10px;
        background: var(--c-bg);
        text-align: center;
    }
    #rotate-hint b { font-size: 18px; font-weight: normal; color: var(--c-accent); letter-spacing: 3px; }
    #rotate-hint span { font-size: 12px; color: var(--c-text-dim); }
}

/* 横持ちで画面が低いときは HUD を縮める */
@media (orientation: landscape) and (max-height: 500px) {
    #hud { transform: scale(0.82); transform-origin: top left; }
    #tracker { transform: scale(0.85); transform-origin: top right; }
    #menu .window { max-height: 92dvh; }
}

/* 画面が狭い端末では HUD を必要最小限にする
   （左下はスティックの領域なので空けておく） */
body.is-touch .stats,
body.is-touch #dbg-fps,
body.is-touch #dbg-pos { display: none; }

body.is-touch .status { width: 190px; }
body.is-touch .debug  { width: auto; }
body.is-touch #log    { width: 260px; font-size: 11px; }

/* ================================================
   タッチ：スキル・薬・メニュー・コンテキスト
   ================================================ */
body.is-touch #skillbar { display: none; }   /* PC用のスキルバーは隠す */

#btn-skills {
    position: absolute;
    right: calc(150px + env(safe-area-inset-right));
    bottom: calc(30px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(2, 68px);
    gap: 8px;
}
.skill-btn {
    position: relative;
    width: 68px; height: 68px;
    border-radius: 50%;
    border: 2px solid var(--c-border);
    background: rgba(8, 14, 22, 0.66);
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 10px;
    line-height: 1.2;
    padding: 0 4px;
    overflow: hidden;
    touch-action: none;
}
.skill-btn.magic { border-color: rgba(92, 225, 255, 0.55); }
.skill-btn.psi   { border-color: rgba(176, 143, 255, 0.6); }
.skill-btn.art   { border-color: rgba(255, 217, 143, 0.5); }
.skill-btn.disabled { opacity: 0.4; }
.skill-btn.on { transform: scale(0.94); }
.skill-btn .cd {
    position: absolute; inset: 0;
    border-radius: 50%;
    pointer-events: none;
}
.skill-btn .nm { position: relative; }

#btn-potion, #btn-menu {
    position: absolute;
    width: 58px; height: 58px;
    border-radius: 50%;
    border: 1px solid var(--c-border);
    background: rgba(8, 14, 22, 0.66);
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 15px;
    touch-action: none;
}
#btn-potion {
    right: calc(30px + env(safe-area-inset-right));
    bottom: calc(148px + env(safe-area-inset-bottom));
    border-color: rgba(143, 217, 74, 0.5);
}
#btn-menu {
    right: calc(14px + env(safe-area-inset-right));
    top: calc(12px + env(safe-area-inset-top));
    font-size: 20px;
}
#btn-potion.on, #btn-menu.on, #btn-context.on { transform: scale(0.94); }

#btn-context {
    position: absolute;
    left: 40%;                /* スキルボタンの島を避けて左寄り */
    bottom: calc(30px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    min-width: 160px;
    min-height: 54px;
    padding: 0 22px;
    border-radius: 27px;
    border: 2px solid var(--c-accent);
    background: rgba(8, 14, 22, 0.8);
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 14px;
    touch-action: none;
    animation: ctxIn 0.16s ease-out;
}
#btn-context.on { transform: translateX(-50%) scale(0.96); }
@keyframes ctxIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* メニューボタンと重ならないよう追跡表示を下げる */
body.is-touch #tracker { top: calc(80px + env(safe-area-inset-top)); width: 220px; }

/* ================================================
   タッチ：メニューと会話
   ================================================ */
#btn-menu-close { display: none; }

body.is-touch #menu .window {
    width: 100%;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    border: none;
}
body.is-touch #menu .mhead {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
}
body.is-touch #menu .close .hint-key { display: none; }
body.is-touch #menu .window { background: rgba(8, 14, 22, 0.95); }
body.is-touch #btn-menu-close {
    display: block;
    background: #1f3346;
    border: 1px solid #2f4760;
    border-radius: 6px;
    padding: 10px 18px;
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 13px;
}
body.is-touch #menu-body {
    padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
    font-size: 13px;
    -webkit-overflow-scrolling: touch;
}
/* 1カラムに並べ直す */
body.is-touch .skills,
body.is-touch .eqgrid { grid-template-columns: 1fr; }
body.is-touch .stats  { grid-template-columns: repeat(5, 1fr); }
body.is-touch .alloc  { grid-template-columns: repeat(3, 1fr); gap: 10px; }
body.is-touch .item   { padding: 10px 12px; }
body.is-touch .item .iname, body.is-touch .eq .ename { font-size: 14px; }
body.is-touch .jname { font-size: 16px; }
body.is-touch .quest p, body.is-touch .skill p, body.is-touch .memo p { font-size: 12px; }

/* 会話は親指で押せる大きさに */
body.is-touch #dialog { padding: 0 12px calc(24px + env(safe-area-inset-bottom)); }
body.is-touch #dlg-text { font-size: 15px; line-height: 1.9; }
body.is-touch #dlg-extra { font-size: 12px; }
body.is-touch #dlg-choices { gap: 10px; }
body.is-touch #dlg-choices button { flex: 1 1 42%; min-height: 56px; font-size: 14px; }
body.is-touch #dlg-choices .num { display: none; }

/* 会話中は操作ボタンを隠す（誤爆防止） */
body.is-touch.in-dialog #btn-attack,
body.is-touch.in-dialog #btn-skills,
body.is-touch.in-dialog #btn-potion,
body.is-touch.in-dialog #btn-context,
body.is-touch.in-dialog #btn-menu { display: none; }

/* 横持ちで画面が低いときはボタンを少し小さく */
@media (orientation: landscape) and (max-height: 400px) {
    #btn-attack { width: 92px; height: 92px; }
    .skill-btn { width: 60px; height: 60px; }
    #btn-skills { right: calc(126px + env(safe-area-inset-right)); }
    #btn-potion { bottom: calc(132px + env(safe-area-inset-bottom)); }
}

/* 開いた直後の数百ミリ秒だけ触れないようにする
   （指を離したときに飛んでくる合成クリックを素通りさせる） */
.arming, .arming * { pointer-events: none !important; }

/* ================================================
   地図
   ================================================ */
#map {
    position: fixed; inset: 0; z-index: 58;
    display: flex; align-items: center; justify-content: center;
    background: rgba(4, 8, 14, 0.75);
    backdrop-filter: blur(2px);
}
#map .box {
    max-height: 94dvh;
    overflow: auto;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 12px 14px 14px;
    animation: boxIn 0.2s ease-out;
}
#map .mhead {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--c-border);
    margin-bottom: 10px;
}
#map-title { font-size: 13px; font-weight: normal; color: var(--c-accent); }
#map .close { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--c-text-dim); }
#btn-map-close {
    display: none;
    background: #1f3346; border: 1px solid #2f4760; border-radius: 6px;
    padding: 8px 16px; color: var(--c-text);
    font-family: var(--font-ui); font-size: 12px;
}
#map-canvas {
    display: block;
    width: min(62vmin, 640px);
    height: min(62vmin, 640px);
    border: 1px solid rgba(120, 180, 255, 0.2);
    border-radius: 4px;
    image-rendering: auto;
}
#map-legend {
    display: flex; flex-wrap: wrap; gap: 12px;
    margin-top: 10px;
    font-size: 11px; color: var(--c-text-dim);
}
#map-legend span { display: flex; align-items: center; gap: 5px; }
#map-legend i {
    display: inline-block; width: 12px; height: 12px;
    border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 2px;
}

/* タッチ端末 */
body.is-touch #btn-map-close { display: block; }
body.is-touch #map .close .hint-key { display: none; }
body.is-touch #map-canvas { width: min(62vmin, 520px); height: min(62vmin, 520px); }

#btn-map {
    position: absolute;
    right: calc(14px + env(safe-area-inset-right));
    top: calc(80px + env(safe-area-inset-top));
    width: 58px; height: 58px;
    border-radius: 50%;
    border: 1px solid var(--c-border);
    background: rgba(8, 14, 22, 0.66);
    color: var(--c-text);
    font-family: var(--font-ui);
    font-size: 13px;
    touch-action: none;
}
#btn-map.on { transform: scale(0.94); }

/* 地図ボタンのぶん、追跡表示をさらに下げる */
body.is-touch #tracker { top: calc(148px + env(safe-area-inset-top)); }

/* 会話中は地図ボタンも隠す */
body.is-touch.in-dialog #btn-map { display: none; }
