* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1d2029; color: #222; font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif; }
/* スマホ：連打での拡大・文字選択・長押しメニュー・引っぱり更新を止める */
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; }
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }

/* 画面の形：スマホ（9:16より縦長）は画面いっぱい。PC・タブレットなど横に広い画面は9:16の枠で中央に出す */
#app { position: relative; width: 100%; height: 100vh; height: 100dvh; max-width: calc(100vh * 9 / 16); max-width: calc(100dvh * 9 / 16); margin: 0 auto; display: flex; flex-direction: column; background: #d9d3c5; overflow: hidden; }
@media (min-aspect-ratio: 9/16) { #app { box-shadow: 0 0 0 1px #2b2f3a, 0 0 40px rgba(0,0,0,.5); } }

/* スマホを横持ちしたとき */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 100; align-items: center; justify-content: center; flex-direction: column; gap: 8px; background: #2b2f3a; color: #fff; font-weight: 700; }
  #rotate span { font-size: 40px; }
}

/* 上の帯 */
#hud { display: flex; align-items: center; gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); background: #2b2f3a; color: #fff; flex: none; }
#hudcenter { flex: 1; min-width: 0; text-align: center; }
#money { font-weight: 800; font-size: 28px; line-height: 1.1; white-space: nowrap; font-variant-numeric: tabular-nums; }
#persec { font-size: 12px; opacity: .75; font-variant-numeric: tabular-nums; }
.hudbtn { flex: none; border: 0; border-radius: 10px; padding: 8px 10px; background: #f0be28; color: #3a2a00; font-weight: 700; font-size: 13px; }
.hudbtn:disabled { background: #555a66; color: #9aa0ab; }
.hudbtn.icon { background: #444a58; color: #fff; font-size: 18px; padding: 6px 10px; }

/* 工場 */
#mapwrap { position: relative; flex: 1; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; }
#map { display: block; touch-action: manipulation; }
.ov { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; padding-bottom: 2px; }
.ov .lv { font-size: 11px; font-weight: 800; color: #fff; background: rgba(30,34,44,.8); border-radius: 6px; padding: 1px 6px; }
.ov button { pointer-events: auto; border: 0; border-radius: 8px; background: #1e6fd9; color: #fff; font-size: 11px; font-weight: 700; padding: 3px 7px; white-space: pre; line-height: 1.25; box-shadow: 0 2px 0 #134a92; font-variant-numeric: tabular-nums; }
.ov button:disabled { background: #8a909c; box-shadow: 0 2px 0 #666; }

/* 下のボタン */
#bottom { display: flex; gap: 6px; padding: 6px 8px; background: #2b2f3a; flex: none; }
#bottom button { flex: 1; border: 0; border-radius: 12px; padding: 12px 0; font-size: 15px; font-weight: 800; color: #fff; background: #3d6fd1; box-shadow: 0 3px 0 #27478a; }
#bottom #btnReb { background: #c98a12; box-shadow: 0 3px 0 #85590a; }
#bottom #btnBox { background: #3c9a5b; box-shadow: 0 3px 0 #276339; }
#credit { flex: none; text-align: center; font-size: 10px; color: #9aa0ab; background: #2b2f3a; padding: 0 0 max(4px, env(safe-area-inset-bottom)); }

/* 下からのシート */
#sheet { position: absolute; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 10; }
#sheet.open { opacity: 1; pointer-events: auto; }
#sheetPanel { width: 100%; max-height: 78%; display: flex; flex-direction: column; background: #f6f3ec; border-radius: 16px 16px 0 0; transform: translateY(20px); transition: transform .15s; }
#sheet.open #sheetPanel { transform: none; }
#sheetHead { display: flex; align-items: center; padding: 12px 16px 8px; font-weight: 800; font-size: 17px; border-bottom: 1px solid #e2ddd1; }
#sheetHead span { flex: 1; }
#sheetClose { border: 0; background: none; font-size: 18px; color: #666; padding: 4px 8px; }
#sheetBody { overflow-y: auto; padding: 8px 16px 20px; }

.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #e7e2d6; }
.row .info { flex: 1; min-width: 0; }
.name { font-weight: 800; font-size: 15px; }
.desc { font-size: 12px; color: #5d6370; overflow-wrap: anywhere; }
.buy { flex: none; min-width: 96px; border: 0; border-radius: 10px; background: #3d6fd1; color: #fff; padding: 6px 8px; display: flex; flex-direction: column; align-items: center; font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; box-shadow: 0 2px 0 #27478a; }
.buy .small { font-size: 10px; font-weight: 600; opacity: .85; }
.buy:disabled { background: #b5b9c2; box-shadow: 0 2px 0 #8d929c; }
.icon { width: 40px; height: 40px; flex: none; border-radius: 6px; border: 2px solid transparent; image-rendering: auto; }
.icon.junk { border-color: #8A8F99; background: #ECEDEF; }
.icon.fan { border-color: #5AB4F0; background: #E1F3FF; }
.icon.talent { border-color: #F0BE28; background: #FFF6D6; }
.note { font-size: 12px; color: #7a7f8a; margin: 10px 0 0; }
.sub { font-weight: 800; font-size: 13px; color: #444; margin: 14px 0 6px; }
.coinhead { font-weight: 800; padding: 6px 0; color: #85590a; }

/* 加工場の詳細 */
.recipe { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.arrow { border: 0; border-radius: 10px; width: 44px; height: 56px; font-size: 22px; background: #2b2f3a; color: #fff; }
.recmid { flex: 1; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fff; border-radius: 12px; padding: 6px; }
.recmid .icon { width: 48px; height: 48px; }
.recname { font-weight: 800; }
.recprice { font-size: 12px; color: #85590a; }
.pending { font-size: 11px; color: #d9531e; font-weight: 700; }
.recinfo { font-size: 12px; color: #5d6370; margin: 6px 0; min-height: 1em; }
.bar { height: 12px; background: #2b2f3a; border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; background: #5ee07a; width: 0; }
.bartext { font-size: 12px; color: #5d6370; margin-top: 3px; }
.stock { display: flex; flex-wrap: wrap; gap: 8px; }
.stk { display: flex; align-items: center; gap: 6px; background: #fff; border-radius: 10px; padding: 4px 8px 4px 4px; font-size: 13px; font-variant-numeric: tabular-nums; }
.stk .icon { width: 30px; height: 30px; }
.arms { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.armlbl { flex: 1; text-align: center; font-weight: 800; padding: 8px 0; border-radius: 10px; background: #fff; }
.armlbl.in { color: #1e6fd9; } .armlbl.out { color: #d9531e; }
.swap { border: 0; border-radius: 10px; padding: 10px 12px; background: #2b2f3a; color: #fff; font-weight: 700; }

/* フォーム・ボタン */
.form { display: flex; flex-direction: column; gap: 8px; }
.form label { display: flex; flex-direction: column; font-size: 12px; color: #5d6370; gap: 3px; }
.form input { font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid #cfc8b8; border-radius: 8px; background: #fff; }
.err { color: #c62828; font-size: 13px; min-height: 1em; }
.primary, .ghost, .danger { border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 800; }
.primary { background: #3d6fd1; color: #fff; }
.ghost { background: #e4dfd3; color: #333; }
.danger { background: #fde7e7; color: #c62828; }
.wide { width: 100%; margin-top: 8px; }
.links { display: flex; justify-content: space-between; margin-top: 6px; }
.link { border: 0; background: none; color: #1e6fd9; padding: 6px 0; font-size: 13px; }
.credit { text-align: center; }

.dlgbg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.dlg { background: #f6f3ec; border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }
.dlg p { white-space: pre-line; margin: 0 0 12px; line-height: 1.5; }
.dlgbtns { display: flex; gap: 8px; justify-content: flex-end; }
.savecard { display: block; width: 100%; text-align: left; border: 2px solid #cfc8b8; background: #fff; border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.savecard:hover { border-color: #3d6fd1; }

#toasts { position: absolute; top: 64px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 40; }
.toast { background: rgba(30,34,44,.92); color: #fff; font-size: 13px; padding: 8px 14px; border-radius: 10px; transition: opacity .5s; max-width: 90%; }
.toast.hide { opacity: 0; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #2b2f3a; color: #fff; z-index: 50; }
