* { box-sizing: border-box; }
:root {
  --bg: #0b1020;
  --card: rgba(14, 20, 39, 0.82);
  --line: rgba(255,255,255,0.09);
  --text: #f6f8ff;
  --muted: #93a0c2;
  --primary: #7d64ff;
  --cyan: #18d7ff;
  --red: #ff5f78;
  --blue: #53a8ff;
  --green: #57cf7d;
  --amber: #ffca68;
  --shadow: 0 24px 60px rgba(0,0,0,0.35);
  --radius: 20px;
}
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
.hidden { display: none !important; }
.glass {
  background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.015)), var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.bg-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(100px);
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}
.bg-glow-a { width: 380px; height: 380px; left: -110px; top: -120px; background: #6546ff; }
.bg-glow-b { width: 450px; height: 450px; right: -160px; bottom: -170px; background: #00b9ff; }

.topbar {
  position: relative;
  z-index: 1;
  margin: 14px;
  height: 70px;
  border-radius: 20px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 900; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--primary), var(--cyan));
}
.brand-title { font-weight: 800; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.badge {
  height: 36px; border-radius: 999px; padding: 0 12px;
  display: flex; align-items: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.main-shell { position: relative; z-index: 1; padding: 0 14px 14px; }
.frame-card { border-radius: var(--radius); padding: 14px; min-height: calc(100vh - 100px); }
.frame-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; margin-bottom: 12px;
}
.eyebrow { font-size: 10px; color: #7d89ac; font-weight: 800; letter-spacing: 0.18em; }
h1, h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: -0.02em; }
.frame-actions, .panel-head-actions, .selection-head-actions { display: flex; gap: 8px; }

.ghost-btn, .primary-btn, .accent-btn, .mini-btn, .restore-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  transition: 0.18s ease;
}
.ghost-btn:hover, .primary-btn:hover, .accent-btn:hover, .mini-btn:hover, .restore-btn:hover { transform: translateY(-1px); }
.ghost-btn { border-radius: 12px; padding: 10px 12px; }
.primary-btn {
  border-radius: 12px; padding: 10px 12px;
  background: linear-gradient(135deg, rgba(125,100,255,0.45), rgba(24,215,255,0.20));
  border-color: rgba(125,100,255,0.35);
}
.accent-btn {
  border-radius: 12px; padding: 10px 12px;
  background: linear-gradient(135deg, rgba(255,95,120,0.35), rgba(255,202,104,0.18));
  border-color: rgba(255,95,120,0.28);
}
.danger { color: #ff9ead; }

.iframe-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--line);
  min-height: calc(100vh - 210px);
  background: #080c16;
}
.iframe-bar {
  height: 42px; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-bottom: 1px solid var(--line);
  background: #0e1321;
}
.dots { display: flex; gap: 5px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; display: block; background: #56617d; }
.dots i:nth-child(1) { background: #ff6479; }
.dots i:nth-child(2) { background: #ffc861; }
.dots i:nth-child(3) { background: #57da88; }
.url-pill {
  margin: 0 auto;
  min-width: 220px;
  max-width: calc(100% - 80px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
#gameFrame {
  display: block;
  width: 100%;
  height: calc(100vh - 252px);
  min-height: 580px;
  border: 0;
  background: #05070d;
}
.frame-note {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  background: rgba(5,8,15,0.90);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.floating-panel {
  position: fixed;
  right: 18px;
  top: 96px;
  width: 380px;
  max-width: calc(100vw - 20px);
  border-radius: 20px;
  z-index: 10;
  overflow: hidden;
}
.panel-head {
  min-height: 58px;
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  cursor: grab;
  border-bottom: 1px solid var(--line);
}
.panel-title { font-weight: 800; margin-top: 3px; }
.mini-btn {
  width: 30px; height: 30px; border-radius: 10px;
}
.panel-body { padding: 14px; }
.status-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.status-card, .stat-box {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
.status-card span, .stat-box span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 5px;
}
.status-card strong, .stat-box strong { font-size: 13px; }

.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.toolbar-grid.secondary { grid-template-columns: 1fr 1fr; }

.tips-box, .result-text, .preview-wrap {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 10px;
}
.tips-box strong { font-size: 12px; }
.tips-box p, .result-text li {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.result-wrap { margin-top: 12px; }
.result-top {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.signal-card, .confidence-card {
  min-height: 96px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  padding: 12px;
}
.signal-card span, .confidence-card span {
  display: block; color: var(--muted); font-size: 11px; margin-bottom: 8px;
}
.signal-card strong, .confidence-card strong { font-size: 28px; line-height: 1; letter-spacing: -0.03em; }
.signal-card small, .confidence-card small { display: block; color: var(--muted); font-size: 11px; margin-top: 8px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
#reasonList { margin: 8px 0 0 18px; padding: 0; }

.preview-wrap canvas {
  display: block;
  width: 100%;
  max-height: 220px;
  background: #05070d;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-top: 8px;
}

.restore-btn {
  position: fixed; right: 18px; bottom: 18px; z-index: 9;
  border-radius: 14px; padding: 12px 14px;
}
.selection-modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(3,6,12,0.72);
  display: grid; place-items: center;
  padding: 14px;
}
.selection-card {
  width: min(100%, 1100px);
  max-height: calc(100vh - 30px);
  border-radius: 20px;
  overflow: hidden;
}
.selection-head {
  padding: 14px 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-bottom: 1px solid var(--line);
}
.selection-help {
  color: var(--muted);
  font-size: 12px;
  padding: 10px 16px 0;
}
.selector-canvas-wrap {
  position: relative;
  padding: 14px 16px 16px;
}
#selectorCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  background: #05070d;
  border: 1px solid var(--line);
  border-radius: 14px;
  touch-action: none;
}
.selection-box {
  position: absolute;
  border: 2px dashed var(--amber);
  background: rgba(255,202,104,0.16);
  pointer-events: none;
  border-radius: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: 0.2s ease;
  pointer-events: none;
  z-index: 30;
  background: #101624;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .topbar { margin: 10px; border-radius: 16px; height: 64px; }
  .brand-sub { display: none; }
  .main-shell { padding: 0 10px 10px; }
  .frame-card { padding: 10px; border-radius: 16px; }
  #gameFrame { min-height: 62vh; height: 62vh; }
  .floating-panel {
    top: auto; right: 10px; left: 10px; bottom: 10px;
    width: auto; max-width: none; border-radius: 18px;
  }
  .panel-head { cursor: default; }
}

@media (max-width: 560px) {
  .top-actions .badge { display: none; }
  .frame-actions .ghost-btn, .top-actions .ghost-btn { padding: 9px 10px; font-size: 12px; }
  .status-row { grid-template-columns: 1fr; }
  .toolbar-grid { grid-template-columns: 1fr 1fr; }
  .result-top { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .signal-card strong, .confidence-card strong { font-size: 24px; }
}