:root {
  --wood: #2a1d12; --wood2: #3a2817; --edge: #8a6a3a; --gold: #e8c46a; --ink: #f4e9d2; --dim: #b9a786;
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px); --sa-r: env(safe-area-inset-right, 0px); --sa-t: env(safe-area-inset-top, 0px);
  --ph: 150px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0f12; color: var(--ink); overscroll-behavior: none;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#game { position: fixed; inset: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* 上部バー */
#top { position: absolute; left: 0; right: 0; top: 0; padding: calc(4px + var(--sa-t)) calc(8px + var(--sa-r)) 4px calc(8px + var(--sa-l));
  display: flex; align-items: center; gap: 6px; background: linear-gradient(#1b130cf0, #1b130cc0); border-bottom: 1px solid var(--edge); z-index: 5; font-family: system-ui, sans-serif; }
.rs { display: flex; align-items: center; gap: 3px; background: #00000055; border: 1px solid #ffffff1a; border-radius: 6px; padding: 2px 6px; font-size: 13px; min-width: 52px; }
.rs span { font-size: 13px; } .rs b { font-variant-numeric: tabular-nums; font-weight: 700; }
.rs.warn { border-color: #ff6a5e; color: #ffb3ac; animation: pulse 1s infinite; }
#age { font-family: "Hiragino Mincho ProN", serif; color: var(--gold); font-size: 13px; white-space: nowrap; }
.grow { flex: 1; }
#clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--dim); }
.tb { background: var(--wood2); border: 1px solid var(--edge); border-radius: 6px; padding: 4px 9px; font-size: 13px; min-width: 38px; min-height: 30px; }

/* 下部パネル */
#panel { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--ph) + var(--sa-b)); padding: 6px calc(6px + var(--sa-r)) calc(6px + var(--sa-b)) calc(6px + var(--sa-l));
  background: linear-gradient(#2a1d12f2, #1b130cf8); border-top: 2px solid var(--edge); box-shadow: 0 -4px 14px #0008; z-index: 5;
  display: grid; grid-template-columns: calc(var(--ph) - 18px) 1fr; grid-template-rows: 40px 1fr; gap: 6px; }
.mmw { grid-row: 1 / 3; border: 2px solid var(--edge); border-radius: 4px; background: #000; overflow: hidden; touch-action: none; }
#mm { width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
#info { min-width: 0; overflow: hidden; font-size: 12px; }
#cmds { display: flex; flex-wrap: wrap; gap: 5px; align-content: flex-start; overflow-y: auto; min-width: 0; }
.cb { width: 54px; height: 50px; border-radius: 7px; border: 1px solid var(--edge); background: linear-gradient(#4a3420, #2f2014); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1px; position: relative; box-shadow: inset 0 1px #ffffff1c; }
.cb:active { transform: translateY(1px); filter: brightness(1.3); }
.cb .ic { font-size: 19px; line-height: 1; font-family: system-ui, sans-serif; }
.cb .lb { font-size: 9.5px; line-height: 1.15; margin-top: 2px; white-space: nowrap; }
.cb .co { font-size: 8px; line-height: 1; color: #f1dca6; font-family: system-ui, sans-serif; white-space: nowrap; letter-spacing: -.3px; }
.cb.no .co { color: #ff8b80; } .cb.no { filter: saturate(.5); }
.cb.lock { opacity: .38; } .cb.lock::after { content: '🔒'; position: absolute; top: 1px; right: 2px; font-size: 9px; }
.cb.on { border-color: #ff8a70; background: linear-gradient(#7a3a24, #4a2012); }
.cb.age { border-color: var(--gold); background: linear-gradient(#6b4e1c, #3e2b0e); }
.one { display: flex; gap: 8px; align-items: center; height: 40px; }
.pt { width: 38px; height: 38px; border-radius: 6px; border: 1px solid var(--edge); background: #1a3a66; display: grid; place-items: center; font-size: 22px; flex: none; font-family: system-ui, sans-serif; }
.pt.foe { background: #6a1f1a; }
.dt { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.dt b { font-size: 13px; color: var(--gold); white-space: nowrap; }
.dt small { color: var(--dim); white-space: nowrap; font-family: system-ui, sans-serif; font-size: 10.5px; }
.foe { color: #ff8b80 !important; }
.bar { display: block; height: 5px; background: #0009; border-radius: 3px; overflow: hidden; max-width: 160px; }
.bar b { display: block; height: 100%; background: #5fdc6a; width: 100%; }
.queue { display: none; }
.multi { display: flex; gap: 4px; overflow-x: auto; height: 40px; }
.mi { height: 38px; min-width: 42px; border: 1px solid var(--edge); background: #00000044; border-radius: 6px; font-size: 18px; display: flex; align-items: center; gap: 2px; padding: 0 5px; font-family: system-ui, sans-serif; }
.mi b { font-size: 11px; }
.hint { color: var(--dim); font-size: 11.5px; line-height: 1.35; padding-top: 2px; }
.qi { position: relative; width: 34px; height: 34px; border: 1px solid var(--edge); background: #00000055; border-radius: 6px; font-size: 17px; padding: 0; font-family: system-ui, sans-serif; flex: none; }
.qi .x { position: absolute; right: -3px; top: -4px; font-size: 8px; background: #8e231d; border-radius: 50%; width: 12px; height: 12px; line-height: 12px; }
.qp { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: #0008; }
.qp b { display: block; height: 100%; background: #7fc8ff; width: 0; }
.wait .qp b { background: #ff8b80; }
.has-queue .one { display: none; }

/* 左のボタン */
#side { position: absolute; left: calc(6px + var(--sa-l)); bottom: calc(var(--ph) + var(--sa-b) + 10px); display: flex; flex-direction: column; gap: 6px; z-index: 4; }
.sb { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--edge); background: #2a1d12e0; font-size: 19px; position: relative; padding: 0; box-shadow: 0 2px 6px #0008; font-family: system-ui, sans-serif; }
.sb i { position: absolute; right: -4px; top: -4px; background: #3a2817; border: 1px solid var(--edge); font-style: normal; font-size: 10px; border-radius: 9px; min-width: 18px; height: 18px; line-height: 16px; padding: 0 3px; }
.sb.hot i { background: #c7432f; border-color: #ffb3a8; animation: pulse 1.2s infinite; }
.sb.on { background: #3f6b3c; border-color: #9effa9; }

/* 配置バー */
#placebar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--ph) + var(--sa-b) + 10px); display: none; gap: 8px; align-items: center; z-index: 6;
  background: #1b130cf0; border: 1px solid var(--gold); border-radius: 12px; padding: 6px 8px 6px 12px; box-shadow: 0 4px 14px #000a; font-family: system-ui, sans-serif; font-size: 12px; white-space: nowrap; }
#placebar.on { display: flex; }
#placebar button { border: 1px solid var(--edge); border-radius: 8px; min-height: 40px; padding: 0 14px; font-size: 14px; }
#b-ok { background: #2f6b33; } #b-cancel { background: #6a2420; }

/* 通知 */
#toasts { position: absolute; top: calc(48px + var(--sa-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 7; pointer-events: none; width: 92%; }
.toast { background: #1b130ce8; border: 1px solid var(--edge); border-radius: 18px; padding: 5px 14px; font-size: 12.5px; transition: opacity .5s, transform .5s; font-family: system-ui, sans-serif; max-width: 100%; text-align: center; }
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast.bad { border-color: #ff6a5e; color: #ffd1cc; } .toast.good { border-color: #7ddc84; }
#tip { position: absolute; left: 50%; transform: translateX(-50%) translateY(10px); bottom: calc(var(--ph) + var(--sa-b) + 66px); max-width: min(520px, 76vw); background: #f4e9d2; color: #3a2817; border-radius: 10px; padding: 8px 12px; font-size: 12.5px; box-shadow: 0 4px 14px #0009; z-index: 4; opacity: 0; pointer-events: none; transition: .4s; border: 2px solid var(--edge); font-family: system-ui, sans-serif; }
#tip.on { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
#b-alert { position: absolute; right: calc(8px + var(--sa-r)); top: calc(48px + var(--sa-t)); z-index: 7; display: none; background: #8e231d; border: 1px solid #ffb3ac; border-radius: 18px; padding: 6px 12px; font-size: 13px; animation: pulse 1s infinite; }
#b-alert.on { display: block; }
#banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: clamp(26px, 7vw, 46px); color: var(--gold); text-shadow: 0 3px 0 #3a2817, 0 0 22px #000; z-index: 8; pointer-events: none; opacity: 0; letter-spacing: .1em; }
#banner.on { animation: bn 3.2s ease forwards; }
@keyframes bn { 0% { opacity: 0; transform: scale(.7); } 15% { opacity: 1; transform: scale(1.05); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pulse { 50% { filter: brightness(1.45); } }

/* オーバーレイ */
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: radial-gradient(ellipse at 50% 30%, #3b2a14d8, #0b0805f2 70%); }
.overlay.hidden, .hidden { display: none !important; }
.card { width: min(440px, 100%); text-align: center; background: linear-gradient(#2e2014, #1c130b); border: 2px solid var(--edge); border-radius: 16px; padding: 22px 20px 18px; box-shadow: 0 10px 40px #000c, inset 0 0 0 4px #00000033; }
.card.small { width: min(320px, 100%); }
.crest { font-size: 38px; color: var(--gold); line-height: 1; }
h1 { margin: 6px 0 2px; font-size: 34px; color: var(--gold); letter-spacing: .12em; text-shadow: 0 2px 0 #000; }
h1.win { color: #ffd76a; } h1.lose { color: #d9a39b; }
h2 { color: var(--gold); margin: 0 0 14px; letter-spacing: .1em; }
.sub { color: var(--dim); font-size: 12px; letter-spacing: .25em; }
.lead { line-height: 1.7; font-size: 14px; margin: 14px 0; }
.diff { display: flex; gap: 6px; justify-content: center; margin: 10px 0 14px; }
.diff button { flex: 1; padding: 9px 0; border-radius: 8px; border: 1px solid var(--edge); background: #00000044; font-size: 14px; }
.diff button.on { background: #6b4e1c; border-color: var(--gold); color: #fff3d0; }
.big { display: block; width: 100%; padding: 13px; font-size: 18px; border-radius: 10px; border: 1px solid var(--gold); background: linear-gradient(#8a5a22, #5a3712); letter-spacing: .1em; box-shadow: 0 3px 0 #2a1806; margin-bottom: 8px; }
.card button:not(.big):not(.link):not(.diff button) { display: block; width: 100%; padding: 11px; font-size: 15px; border-radius: 10px; border: 1px solid var(--edge); background: #00000044; margin-bottom: 8px; }
.link { background: none; border: none; color: var(--dim); text-decoration: underline; font-size: 13px; padding: 6px; }
#howto { text-align: left; font-size: 12.5px; line-height: 1.6; background: #00000040; border-radius: 10px; padding: 8px 12px; margin-top: 6px; font-family: system-ui, sans-serif; }
#howto ul { margin: 0; padding-left: 16px; } #howto p { margin: 6px 0; } .pc { color: var(--dim); }
.rot { color: var(--dim); font-size: 11px; margin: 10px 0 0; font-family: system-ui, sans-serif; }
#endStats { width: 100%; border-collapse: collapse; margin: 6px 0 16px; font-family: system-ui, sans-serif; font-size: 13px; }
#endStats th { color: var(--gold); font-weight: normal; padding: 4px; }
#endStats td { padding: 5px 4px; border-top: 1px solid #ffffff14; }
#endStats td:first-child { text-align: left; color: var(--dim); }
#endStats .tm { text-align: center !important; color: var(--dim); padding-top: 10px; }

/* 横向き・低い画面 */
@media (max-height: 520px) {
  :root { --ph: 112px; }
  #panel { grid-template-columns: calc(var(--ph) - 14px) minmax(150px, 210px) 1fr; grid-template-rows: 1fr; }
  .mmw { grid-row: auto; }
  #info { display: flex; flex-direction: column; gap: 4px; }
  .has-queue .one { display: flex; }
  #top { padding-top: calc(2px + var(--sa-t)); padding-bottom: 2px; }
  .rs { font-size: 12px; min-width: 46px; padding: 1px 5px; }
  .cb { width: 50px; height: 47px; }
  #side { gap: 5px; }
  .sb { width: 40px; height: 40px; font-size: 17px; }
  #tip { bottom: calc(var(--ph) + var(--sa-b) + 58px); }
  .card { padding: 14px 16px; } h1 { font-size: 26px; } .lead { margin: 8px 0; font-size: 13px; } .crest { display: none; }
}
@media (max-width: 420px) {
  .rs { min-width: 0; padding: 2px 4px; font-size: 12px; gap: 1px; }
  .rs span { font-size: 11px; }
  #age { display: none; }
  #clock { display: none; }
}
#info .queue { display: flex; gap: 4px; margin-top: 2px; }
