@font-face {
  font-family: 'SpaceMono';
  src: url('assets/fonts/SpaceMono-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SpaceMono';
  src: url('assets/fonts/SpaceMono-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --slate-bg: #16201c;
  --slate-panel: rgba(17, 27, 23, 0.86);
  --slate-card: rgba(24, 37, 31, 0.94);
  --chalk-white: #f3f1e6;
  --chalk-muted: #b3c0b8;
  --chalk-yellow: #fde068;
  --chalk-cyan: #67e8f9;
  --chalk-coral: #fb7185;
  --chalk-mint: #6ee7b7;
  --chalk-pink: #f472b6;
  --chalk-orange: #fb923c;
  --chalk-border: rgba(243, 241, 230, 0.34);
  --font-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-mono: 'SpaceMono', "PingFang SC", "Microsoft YaHei", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--slate-bg);
  color: var(--chalk-white);
  font-family: var(--font-ui);
  user-select: none;
}

.mono {
  font-family: var(--font-mono);
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 0;
  pointer-events: none;
  touch-action: none;
}

#particles-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 15;
  pointer-events: none;
  touch-action: none;
}

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  overflow: hidden;
}

/* Chalk Borders & Panels */
.chalk-box {
  background: var(--slate-panel);
  border: 2px dashed var(--chalk-border);
  border-radius: 12px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.38), inset 0 0 0 1px rgba(243, 241, 230, 0.08);
}

/* Top HUD */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.brand-badge {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--chalk-yellow);
  padding: 5px 11px;
  border: 2px solid rgba(253, 224, 104, 0.55);
  border-radius: 8px;
  background: rgba(253, 224, 104, 0.09);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}

.stat-pill {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(16, 26, 22, 0.85);
  border: 1px solid rgba(243, 241, 230, 0.25);
  color: var(--chalk-white);
  white-space: nowrap;
}

.coin-pill {
  color: var(--chalk-yellow);
  border-color: rgba(253, 224, 104, 0.4);
}

.score-pill {
  color: var(--chalk-cyan);
  border-color: rgba(103, 232, 249, 0.35);
}

.combo-pill {
  color: var(--chalk-muted);
  border-color: rgba(243, 241, 230, 0.22);
}

.combo-pill.hot {
  color: var(--chalk-orange);
  border-color: rgba(251, 146, 60, 0.7);
  background: rgba(251, 146, 60, 0.14);
}

/* Modules Strip */
.modules-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  min-width: 180px;
  overflow-x: auto;
  scrollbar-width: none;
}

.modules-strip::-webkit-scrollbar {
  display: none;
}

.module-slot {
  padding: 5px 9px;
  border-radius: 7px;
  font-size: 12px;
  border: 1.5px dashed rgba(243, 241, 230, 0.22);
  background: rgba(14, 22, 19, 0.72);
  color: rgba(243, 241, 230, 0.42);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: default;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.module-slot.filled {
  border-style: solid;
  color: var(--chalk-white);
  background: rgba(24, 39, 33, 0.94);
  cursor: pointer;
  font-weight: 600;
}

.module-slot.filled:hover {
  transform: translateY(-2px);
}

/* Buttons (Touch-friendly min height) */
.chalk-btn {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 2px solid var(--chalk-border);
  background: rgba(24, 36, 31, 0.92);
  color: var(--chalk-white);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  touch-action: manipulation;
}

.chalk-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--chalk-white);
}

.chalk-btn:active:not(:disabled) {
  transform: translateY(0);
}

.chalk-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn-primary {
  background: rgba(253, 224, 104, 0.18);
  border-color: var(--chalk-yellow);
  color: var(--chalk-yellow);
}

.btn-primary:hover:not(:disabled) {
  background: rgba(253, 224, 104, 0.28);
}

.btn-coral {
  background: rgba(251, 113, 133, 0.14);
  border-color: var(--chalk-coral);
  color: var(--chalk-coral);
}

.btn-coral:hover:not(:disabled) {
  background: rgba(251, 113, 133, 0.25);
}

.btn-cyan {
  background: rgba(103, 232, 249, 0.14);
  border-color: var(--chalk-cyan);
  color: var(--chalk-cyan);
}

.btn-cyan:hover:not(:disabled) {
  background: rgba(103, 232, 249, 0.24);
}

.btn-secondary {
  background: rgba(243, 241, 230, 0.08);
  border-color: rgba(243, 241, 230, 0.38);
}

.btn-danger-outline {
  background: rgba(251, 113, 133, 0.08);
  border-color: rgba(251, 113, 133, 0.48);
  color: #fda4af;
}

.btn-lg {
  font-size: 16px;
  min-height: 46px;
  padding: 11px 24px;
}

/* Main Stage */
#stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 0.82fr) minmax(360px, 1.38fr);
  gap: 12px;
  align-items: stretch;
}

/* Enemy Panel */
.enemy-panel {
  padding: 12px 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.enemy-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.enemy-round-tag {
  font-size: 13px;
  color: var(--chalk-cyan);
  font-weight: 700;
}

.enemy-hp-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--chalk-coral);
}

.enemy-visual-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.enemy-sigil-wrap {
  width: 96px;
  height: 96px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px dashed rgba(103, 232, 249, 0.32);
  background: rgba(11, 18, 15, 0.65);
  transition: transform 0.15s ease;
}

.enemy-sigil-wrap.hit {
  animation: enemy-shake 0.32s ease;
}

.enemy-sigil-wrap.shield-broken {
  border-color: var(--chalk-yellow);
  box-shadow: 0 0 22px rgba(253, 224, 104, 0.38);
}

@keyframes enemy-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-3deg); }
  50% { transform: translateX(8px) rotate(3deg); }
  75% { transform: translateX(-4px); }
}

.enemy-sigil {
  width: 80px;
  height: 80px;
}

.enemy-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.enemy-name {
  font-size: 21px;
  font-weight: 800;
  color: var(--chalk-white);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  overflow-wrap: break-word;
}

.hp-bar-track {
  width: 100%;
  height: 13px;
  border-radius: 8px;
  background: rgba(8, 14, 12, 0.85);
  border: 1.5px solid rgba(243, 241, 230, 0.35);
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #fb7185, #f43f5e);
  transition: width 0.32s ease;
}

.shield-box {
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(103, 232, 249, 0.08);
  border: 1.5px solid rgba(103, 232, 249, 0.45);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.shield-box.matched {
  background: rgba(253, 224, 104, 0.14);
  border-color: var(--chalk-yellow);
  box-shadow: 0 0 14px rgba(253, 224, 104, 0.22);
}

.shield-title {
  font-size: 11px;
  color: var(--chalk-muted);
  letter-spacing: 0.05em;
}

.shield-cond {
  font-size: 18px;
  font-weight: 700;
  color: var(--chalk-cyan);
}

.shield-second {
  font-size: 13px;
  font-weight: 700;
  color: #fde068;
}

.shield-second.met {
  color: var(--chalk-mint);
}

.shield-box.matched .shield-cond {
  color: var(--chalk-yellow);
}

.shield-hint {
  font-size: 12px;
  color: var(--chalk-muted);
  line-height: 1.35;
}

/* Enemy Defensive States */
.defense-states[hidden],
.preview-defense[hidden] {
  display: none;
}

.defense-states {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px dashed rgba(243, 241, 230, 0.18);
}

.defense-states-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.defense-states-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--chalk-muted);
  letter-spacing: 0.04em;
}

.defense-rotate-hint {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--chalk-cyan);
  background: rgba(103, 232, 249, 0.1);
  border: 1px dashed rgba(103, 232, 249, 0.45);
  white-space: nowrap;
}

.defense-badges {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.defense-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(10, 17, 14, 0.78);
  border: 1.5px dashed rgba(243, 241, 230, 0.35);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.defense-badge.countered {
  background: rgba(110, 231, 183, 0.12);
  border-style: solid;
  border-color: var(--chalk-mint) !important;
  box-shadow: 0 0 12px rgba(110, 231, 183, 0.18);
}

.defense-badge.blocked {
  background: rgba(251, 113, 133, 0.13);
  border-style: solid;
  border-color: var(--chalk-coral) !important;
  box-shadow: 0 0 12px rgba(251, 113, 133, 0.18);
}

.defense-badge-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.defense-badge-name {
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.defense-badge-status {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.defense-badge-status.ok {
  color: var(--chalk-mint);
  background: rgba(110, 231, 183, 0.14);
}

.defense-badge-status.warn {
  color: var(--chalk-coral);
  background: rgba(251, 113, 133, 0.14);
}

.defense-badge-status.regen {
  color: var(--chalk-orange);
  background: rgba(251, 146, 60, 0.14);
}

.defense-badge-desc {
  font-size: 11.5px;
  color: var(--chalk-muted);
  line-height: 1.35;
}

/* Terminal Panel */
.terminal-panel {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.terminal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.terminal-top-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.selection-count {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(253, 224, 104, 0.14);
  border: 1px solid rgba(253, 224, 104, 0.45);
  color: var(--chalk-yellow);
}

.selection-count.full {
  background: rgba(251, 113, 133, 0.18);
  border-color: var(--chalk-coral);
  color: var(--chalk-coral);
}

.terminal-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--chalk-yellow);
}

.terminal-tip {
  font-size: 12px;
  color: var(--chalk-muted);
}

.formula-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 7px 11px;
  border-radius: 10px;
  background: rgba(10, 17, 14, 0.72);
  border: 1.5px dashed rgba(243, 241, 230, 0.28);
}

.formula-slots {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.formula-placeholder {
  font-size: 14px;
  color: rgba(243, 241, 230, 0.42);
}

.formula-chip {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  min-height: 36px;
  padding: 5px 11px;
  border-radius: 8px;
  background: rgba(243, 241, 230, 0.1);
  border: 1.5px solid var(--chalk-white);
  color: var(--chalk-white);
  cursor: pointer;
}

.formula-chip.op {
  border-color: var(--chalk-cyan);
  color: var(--chalk-cyan);
  background: rgba(103, 232, 249, 0.12);
}

.formula-equals {
  font-size: 22px;
  font-weight: 700;
  color: var(--chalk-yellow);
  white-space: nowrap;
}

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(243, 241, 230, 0.05);
}

.preview-mod {
  font-size: 13px;
  font-weight: 700;
  color: var(--chalk-muted);
}

.preview-mod.hit {
  color: var(--chalk-yellow);
}

.preview-mod.near {
  color: var(--chalk-mint);
}

.preview-traits {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.trait-preview-tag {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.25);
}

.preview-defense {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(10, 17, 14, 0.62);
  border: 1px dashed rgba(243, 241, 230, 0.2);
}

.defense-preview-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.28);
}

.defense-preview-tag.ok {
  color: var(--chalk-mint);
}

.defense-preview-tag.warn {
  color: var(--chalk-coral);
}

.defense-preview-tag.regen {
  color: var(--chalk-orange);
}

.preview-calc {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(253, 224, 104, 0.08);
  border: 1px solid rgba(253, 224, 104, 0.28);
  color: var(--chalk-muted);
  line-height: 1.45;
  overflow-wrap: break-word;
}

.preview-calc.ready {
  color: var(--chalk-yellow);
  border-color: rgba(253, 224, 104, 0.55);
}

.preview-calc.reduced {
  border-color: rgba(251, 113, 133, 0.65);
  background: rgba(251, 113, 133, 0.09);
  color: #fecdd3;
}

/* Scanner Cascade Stage */
.scanner-stage {
  flex: 1;
  min-height: 68px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(11, 18, 15, 0.65);
  border: 1px solid rgba(243, 241, 230, 0.16);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  overflow-y: auto;
}

.scanner-idle {
  font-size: 13px;
  color: var(--chalk-muted);
  text-align: center;
  line-height: 1.45;
}

.scanner-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.scan-pill {
  padding: 4px 9px;
  border-radius: 8px;
  border: 1.5px solid currentColor;
  background: rgba(18, 28, 24, 0.92);
  font-size: 12px;
  font-weight: 700;
  animation: pop-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.scan-pill.defense-break {
  background: rgba(110, 231, 183, 0.14);
  box-shadow: 0 0 10px rgba(110, 231, 183, 0.2);
}

.scan-pill.defense-block {
  background: rgba(251, 113, 133, 0.16);
  border-style: dashed;
}

@keyframes pop-in {
  0% { transform: scale(0.65); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.scanner-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--chalk-yellow);
  text-align: right;
  line-height: 1.35;
}

/* Hand Dock */
#hand-dock {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.hand-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.counters-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.counter-chip {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--slate-panel);
  border: 1.5px solid rgba(243, 241, 230, 0.28);
}

.plays-chip {
  color: var(--chalk-mint);
  border-color: rgba(110, 231, 183, 0.45);
}

.discards-chip {
  color: var(--chalk-coral);
  border-color: rgba(251, 113, 133, 0.45);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hand-cards {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  padding: 4px 2px 2px;
  min-height: 98px;
}

.operator-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.op-btn {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 800;
  min-width: 56px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 9px;
  border: 1.5px solid rgba(103, 232, 249, 0.58);
  background: rgba(18, 36, 40, 0.94);
  color: var(--chalk-cyan);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.op-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--chalk-white);
  background: rgba(25, 52, 58, 0.96);
}

.op-btn:active:not(:disabled) {
  transform: translateY(0);
}

.op-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.op-btn.op-concat {
  font-family: var(--font-ui);
  font-size: 14px;
  border-color: rgba(253, 224, 104, 0.58);
  color: var(--chalk-yellow);
  background: rgba(34, 32, 18, 0.92);
}

.play-card {
  position: relative;
  width: clamp(78px, 12vw, 108px);
  height: 94px;
  border-radius: 12px;
  background: var(--slate-card);
  border: 2px solid rgba(243, 241, 230, 0.48);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.42);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
  touch-action: manipulation;
}

.play-card:hover {
  transform: translateY(-5px);
  border-color: var(--chalk-white);
}

.play-card.operator-card {
  border-color: rgba(103, 232, 249, 0.58);
  background: rgba(18, 36, 40, 0.94);
}

.play-card.selected {
  transform: translateY(-12px);
  border-color: var(--chalk-yellow);
  box-shadow: 0 10px 22px rgba(253, 224, 104, 0.28);
}

.card-order-badge {
  position: absolute;
  top: -9px;
  right: -7px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--chalk-yellow);
  color: #141c18;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.card-key-hint {
  position: absolute;
  top: 5px;
  left: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(243, 241, 230, 0.35);
}

.card-main {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--chalk-white);
}

.play-card.operator-card .card-main {
  color: var(--chalk-cyan);
  font-size: 23px;
}

.card-sub {
  font-size: 11px;
  color: var(--chalk-muted);
}

/* Overlays / Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 16, 13, 0.76);
  backdrop-filter: blur(3px);
}

.modal-overlay.active {
  display: flex;
}

.chalk-modal {
  width: min(820px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 22px;
  border-radius: 16px;
  background: rgba(20, 31, 26, 0.97);
  border: 2.5px dashed rgba(243, 241, 230, 0.45);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.title-modal {
  width: min(580px, 100%);
  text-align: center;
  align-items: center;
}

.title-eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--chalk-cyan);
}

.game-title {
  font-size: clamp(34px, 7vw, 48px);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--chalk-yellow);
  text-shadow: 0 3px 12px rgba(253, 224, 104, 0.25);
}

.title-subtitle {
  font-size: 15px;
  line-height: 1.65;
  color: var(--chalk-white);
  max-width: 460px;
}

.title-formula-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(12, 20, 17, 0.8);
  border: 1px dashed rgba(103, 232, 249, 0.4);
  font-size: 13px;
  color: var(--chalk-cyan);
}

.title-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.title-best {
  font-size: 13px;
  color: var(--chalk-muted);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--chalk-yellow);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--chalk-muted);
  margin-top: 3px;
  line-height: 1.45;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* Rules Modal */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rule-card {
  padding: 12px 14px;
  border-radius: 11px;
  background: rgba(13, 21, 18, 0.9);
  border: 1.5px solid rgba(243, 241, 230, 0.22);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule-card-wide {
  grid-column: 1 / -1;
}

.rule-card-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--chalk-yellow);
}

.rule-card-body {
  font-size: 13px;
  line-height: 1.65;
  color: var(--chalk-white);
}

.rule-card-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(243, 241, 230, 0.1);
  color: var(--chalk-cyan);
}

.hl-yellow {
  color: var(--chalk-yellow);
}

.hl-cyan {
  color: var(--chalk-cyan);
}

/* Shop */
.shop-wallet {
  font-size: 15px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--chalk-yellow);
  color: var(--chalk-yellow);
  white-space: nowrap;
}

.shop-owned-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shop-section-label {
  font-size: 12px;
  color: var(--chalk-muted);
}

.shop-owned-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.shop-offers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.offer-card {
  padding: 12px;
  border-radius: 12px;
  background: rgba(14, 23, 19, 0.9);
  border: 2px solid rgba(243, 241, 230, 0.28);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.offer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.offer-name {
  font-size: 15px;
  font-weight: 800;
}

.offer-rarity {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.offer-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--chalk-muted);
  flex: 1;
}

.shop-upgrade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: 11px;
  background: rgba(103, 232, 249, 0.08);
  border: 1.5px dashed rgba(103, 232, 249, 0.45);
}

.shop-upgrade-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--chalk-cyan);
}

.shop-upgrade-desc {
  font-size: 12px;
  color: var(--chalk-muted);
  margin-top: 2px;
}

/* Property Guide Grid */
.guide-progress {
  font-size: 13px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid rgba(103, 232, 249, 0.45);
  color: var(--chalk-cyan);
  background: rgba(103, 232, 249, 0.1);
}

.guide-tabs {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.guide-tab {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid rgba(243, 241, 230, 0.25);
  background: rgba(14, 22, 19, 0.85);
  color: var(--chalk-muted);
  cursor: pointer;
}

.guide-tab.active {
  border-color: var(--chalk-yellow);
  color: var(--chalk-yellow);
  background: rgba(253, 224, 104, 0.14);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.guide-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(13, 21, 18, 0.88);
  border: 1.5px solid rgba(243, 241, 230, 0.2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guide-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.guide-item-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.guide-item-name {
  font-size: 15px;
  font-weight: 800;
}

.guide-rarity-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.guide-item-bonus {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--chalk-yellow);
}

.guide-item-rule {
  font-size: 12px;
  color: var(--chalk-white);
  line-height: 1.45;
}

.guide-item-ex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--chalk-muted);
  overflow-wrap: break-word;
}

/* End Modal */
.end-modal {
  width: min(500px, 100%);
  text-align: center;
  align-items: center;
}

.end-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--chalk-coral);
  color: var(--chalk-coral);
}

.end-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.end-stat-box {
  padding: 10px;
  border-radius: 10px;
  background: rgba(13, 21, 18, 0.85);
  border: 1px solid rgba(243, 241, 230, 0.2);
}

.end-stat-label {
  font-size: 12px;
  color: var(--chalk-muted);
}

.end-stat-val {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--chalk-yellow);
  margin-top: 2px;
}

/* Tooltip */
.chalk-tooltip {
  position: fixed;
  z-index: 40;
  max-width: 240px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(13, 20, 17, 0.96);
  border: 1.5px solid var(--chalk-yellow);
  color: var(--chalk-white);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
}

/* ============================================================
   Tablet & Portrait Pad (<= 960px width or portrait aspect)
   ============================================================ */
@media (max-width: 960px) {
  #stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 9px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .hud-bar {
    gap: 6px;
  }

  .modules-strip {
    order: 3;
    flex: 1 0 100%;
    justify-content: flex-start;
    padding-bottom: 2px;
  }

  .enemy-sigil-wrap {
    width: 78px;
    height: 78px;
  }

  .enemy-sigil {
    width: 64px;
    height: 64px;
  }

  .shop-offers {
    grid-template-columns: 1fr;
  }

  .hand-cards {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: safe center;
  }
}

/* ============================================================
   Mobile Phone Portrait (<= 640px width)
   ============================================================ */
@media (max-width: 640px) {
  #app {
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    gap: 7px;
  }

  .brand-badge {
    font-size: 14px;
    padding: 4px 8px;
  }

  .stat-pill {
    font-size: 11px;
    padding: 4px 7px;
  }

  .hud-right .chalk-btn {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .enemy-panel,
  .terminal-panel {
    padding: 10px 11px;
    gap: 6px;
  }

  .enemy-sigil-wrap {
    width: 64px;
    height: 64px;
  }

  .enemy-sigil {
    width: 52px;
    height: 52px;
  }

  .enemy-name {
    font-size: 17px;
  }

  .shield-cond {
    font-size: 15px;
  }

  .defense-badge {
    padding: 5px 8px;
  }

  .defense-badge-name {
    font-size: 12px;
  }

  .defense-badge-desc {
    font-size: 11px;
  }

  .preview-defense {
    padding: 4px 8px;
    gap: 5px;
  }

  .defense-preview-tag {
    font-size: 11px;
    padding: 2px 6px;
  }

  .formula-row {
    min-height: 46px;
    padding: 6px 9px;
  }

  .formula-chip {
    font-size: 15px;
    min-height: 34px;
    padding: 4px 9px;
  }

  .formula-equals {
    font-size: 18px;
  }

  .preview-calc {
    font-size: 12px;
    padding: 5px 8px;
  }

  .scanner-stage {
    min-height: 56px;
    padding: 7px 9px;
  }

  .hand-meta-row {
    gap: 6px;
  }

  .counter-chip {
    font-size: 12px;
    padding: 5px 8px;
  }

  .action-buttons {
    width: 100%;
    justify-content: space-between;
  }

  .action-buttons .chalk-btn {
    flex: 1;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 14px;
  }

  /* 5-column touch grid for 5 number cards + 5-column operator bar on portrait phones */
  .operator-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .op-btn {
    min-width: 0;
    width: 100%;
    min-height: 38px;
    padding: 4px 2px;
    font-size: 17px;
  }

  .op-btn.op-concat {
    font-size: 12px;
  }

  .hand-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    padding: 2px 0 0;
    min-height: 0;
    overflow-x: visible;
  }

  .play-card {
    width: 100%;
    height: 74px;
    gap: 2px;
    border-radius: 10px;
  }

  .play-card.selected {
    transform: translateY(-4px);
  }

  .card-main {
    font-size: 22px;
  }

  .play-card.operator-card .card-main {
    font-size: 18px;
  }

  .card-sub {
    font-size: 10px;
  }

  .card-key-hint {
    display: none;
  }

  .chalk-modal {
    padding: 16px 14px;
    gap: 12px;
  }

  .rules-grid,
  .guide-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Short Mobile Landscape (max-height <= 520px)
   ============================================================ */
@media (max-height: 520px) {
  #app {
    padding: 6px 10px;
    gap: 5px;
  }

  #stage {
    grid-template-columns: minmax(230px, 0.78fr) minmax(320px, 1.42fr);
    grid-template-rows: 1fr;
    gap: 8px;
  }

  .hud-bar {
    gap: 5px;
  }

  .modules-strip {
    order: 0;
    flex: 1;
    min-width: 120px;
  }

  .brand-badge {
    font-size: 13px;
    padding: 3px 8px;
  }

  .stat-pill,
  .module-slot,
  .counter-chip {
    font-size: 11px;
    padding: 3px 7px;
  }

  .chalk-btn {
    min-height: 34px;
    font-size: 12px;
    padding: 4px 10px;
  }

  .enemy-panel,
  .terminal-panel {
    padding: 7px 10px;
    gap: 4px;
  }

  .enemy-sigil-wrap {
    width: 52px;
    height: 52px;
  }

  .enemy-sigil {
    width: 40px;
    height: 40px;
  }

  .enemy-name {
    font-size: 15px;
  }

  .shield-box {
    padding: 4px 8px;
  }

  .shield-cond {
    font-size: 14px;
  }

  .shield-hint,
  .terminal-tip {
    font-size: 10px;
  }

  .defense-states {
    gap: 3px;
    padding-top: 2px;
  }

  .defense-badge {
    padding: 3px 7px;
  }

  .defense-badge-name,
  .defense-rotate-hint {
    font-size: 10.5px;
  }

  .defense-badge-desc {
    font-size: 10px;
  }

  .formula-row {
    min-height: 38px;
    padding: 4px 8px;
  }

  .formula-chip {
    font-size: 14px;
    min-height: 28px;
    padding: 2px 8px;
  }

  .formula-equals {
    font-size: 17px;
  }

  .preview-bar {
    padding: 3px 8px;
  }

  .preview-defense {
    padding: 3px 7px;
    gap: 4px;
  }

  .defense-preview-tag {
    font-size: 10.5px;
    padding: 1px 6px;
  }

  .preview-mod,
  .preview-calc {
    font-size: 11px;
    padding: 3px 8px;
  }

  .scanner-stage {
    min-height: 40px;
    padding: 5px 8px;
    gap: 4px;
  }

  .scanner-idle {
    font-size: 11px;
  }

  .operator-bar {
    gap: 6px;
  }

  .op-btn {
    min-height: 30px;
    min-width: 44px;
    padding: 2px 10px;
    font-size: 15px;
  }

  .op-btn.op-concat {
    font-size: 12px;
  }

  .hand-cards {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    min-height: 64px;
    padding: 2px 2px 0;
    gap: 6px;
  }

  .play-card {
    width: clamp(68px, 11vw, 88px);
    height: 62px;
    gap: 2px;
  }

  .play-card.selected {
    transform: translateY(-6px);
  }

  .card-main {
    font-size: 20px;
  }

  .play-card.operator-card .card-main {
    font-size: 16px;
  }

  .card-sub {
    font-size: 10px;
  }
}
