:root { --bg: #171126; --panel: #261b3d; --panel2: #38285a; --line: #55407f; --accent: #ff9f43; --accent-ink: #2e1400; --cell: 62px; }
#app { position: fixed; inset: 0; display: grid; gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto auto; grid-template-areas: "top" "battle" "gear" "info" "actions"; }
#top { grid-area: top; display: flex; align-items: center; gap: 6px; min-width: 0; }
#top .sp { flex: 1; }
.stat { display: flex; align-items: center; gap: 4px; padding: 4px 9px; min-height: 34px; background: #0005; border-radius: 10px; font-weight: 700; white-space: nowrap; }
.stat img { width: 20px; height: 20px; }
.stat.ember { color: #ffb37a; }
#battle { grid-area: battle; position: relative; border-radius: 12px; overflow: hidden; border: 3px solid #a98a4a; min-height: 0; background: #223; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#info { grid-area: info; min-height: 40px; padding: 4px 10px; background: #0004; border-radius: 10px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
#info b { color: var(--accent); }
#info .btn { min-height: 34px; padding: 2px 10px; font-size: 13px; margin-left: auto; flex: none; }
#actions { grid-area: actions; display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; }
#actions .btn { padding: 0 2px; min-height: 52px; line-height: 1.05; }
#actions b { display: block; }
#actions small { font-size: 12px; opacity: .85; }
#gear { grid-area: gear; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#slots { display: grid; grid-template-columns: repeat(5, var(--cell)); gap: 3px; width: max-content; }
#board { display: grid; grid-template-columns: repeat(6, var(--cell)); grid-auto-rows: var(--cell); gap: 3px; touch-action: none; width: max-content; }
#slots { grid-template-columns: repeat(5, calc(var(--cell) * 1.2 + .5px)); grid-auto-rows: var(--cell); touch-action: none; }
.cell, .slot { position: relative; border-radius: 9px; background: radial-gradient(#2c2340, #17112a 78%); box-shadow: inset 0 0 0 2px #a98a4a55, inset 0 2px 7px #000a; display: grid; place-items: center; }
.slot img.outline { position: absolute; inset: 12%; width: 76%; height: 76%; object-fit: contain; filter: grayscale(1) brightness(.5); opacity: .5; }
.cell.locked { background: repeating-linear-gradient(45deg, #0003 0 7px, #0006 7px 14px); color: var(--dim); font-size: 19px; cursor: pointer; }
.cell.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.cell.can, .slot.can { box-shadow: inset 0 0 0 3px var(--good); background: #2c6a4a55; }
.slot { background: radial-gradient(#3b2c5e, #1c1433 80%); box-shadow: inset 0 0 0 2px #d9b35a88, inset 0 2px 7px #000a; }
.slot .ph { position: absolute; bottom: 1px; font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .4px; }
.slot.trash { background: #5c2a3488; font-size: 22px; color: #ffb0b0; }
.it { position: relative; width: 90%; height: 90%; pointer-events: none; }
.it img { width: 100%; height: 100%; display: block; object-fit: contain; filter: drop-shadow(0 2px 2px #000a); }
.it i { position: absolute; right: -1px; bottom: -1px; min-width: 18px; padding: 0 3px; font: 800 11px/16px "Trebuchet MS", Arial; text-align: center; background: #000b; color: #fff; border-radius: 6px; }
.it.pop { animation: popin .26s cubic-bezier(.2, 1.7, .5, 1); }
.it.wig { animation: wig 1s infinite; }
@keyframes popin { from { transform: scale(.25); } }
@keyframes wig { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
#ghost { position: fixed; z-index: 45; width: calc(var(--cell) * 1.15); height: calc(var(--cell) * 1.15); pointer-events: none; transform: translate(-50%, -60%); filter: drop-shadow(0 6px 5px #000a); }
#ghost img { width: 100%; height: 100%; }

/* phones held upright */
@media (orientation: portrait) { :root { --cell: min(15.2vw, 13vh, 84px); } #battle { min-height: 120px; } }

/* wide screens: gear block on the right at full height */
@media (orientation: landscape) {
  :root { --cell: min(calc((100dvh - 28px) / 5), 8.7vw, 92px); }
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "top gear" "battle gear" "info gear" "actions gear"; }
  #gear { flex-direction: row; align-self: center; }
  #slots { grid-template-columns: var(--cell); }
  #info { font-size: 12px; min-height: 34px; }
  #actions .btn { min-height: 48px; }
}
@media (orientation: landscape) and (max-height: 430px) {
  :root { --cell: min(calc((100dvh - 28px) / 5), 9.2vw); }
  #top .stat { padding: 2px 6px; font-size: 13px; min-height: 28px; }
  #top .st, #top .ember { display: none; }
  #app { grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top gear" "battle gear" "actions gear"; }
  #info { display: none; font-size: 12px; }
  #info.show { display: flex; position: fixed; z-index: 5; left: max(10px, env(safe-area-inset-left)); bottom: 62px; width: min(38vw, 300px); background: #000d; }
  #actions { gap: 4px; }
  #actions .btn { font-size: 11.5px; min-height: 46px; border-width: 7px 7px; padding: 0; }
  #actions small { font-size: 10px; }
}
