:root {
  --bg: #070b14;
  --panel: #0f172a;
  --panel-border: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #06b6d4;
  --gold: #fbbf24;
  --success: #10b981;
  --danger: #f43f5e;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  background: radial-gradient(circle at top, #131c36 0%, var(--bg) 62%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.app-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #06b6d4, #6366f1);
  font-size: 20px;
  box-shadow: 0 0 18px rgba(99, 102, 241, 0.45);
}

.brand h1 {
  font-size: 19px;
  letter-spacing: 0.08em;
  line-height: 1.1;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.security-pill {
  font-size: 12px;
  color: #67e8f9;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.35);
  border-radius: 999px;
  padding: 5px 10px;
}

.security-pill.active {
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.4);
}

.security-pill.offline {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #818cf8, var(--primary));
}

.btn-accent {
  background: linear-gradient(135deg, #06b6d4, #0284c7);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #22d3ee, #0284c7);
}

.btn-ghost {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid #334155;
}

.btn-ghost:hover:not(:disabled) {
  background: #334155;
}

.btn-lg {
  padding: 11px 24px;
  font-size: 15px;
}

.btn-icon {
  background: transparent;
  border: 1px solid #334155;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.btn-icon:hover {
  color: var(--text);
  border-color: #64748b;
}

.arena {
  display: grid;
  grid-template-columns: 220px minmax(280px, 324px) 260px;
  justify-content: center;
  align-items: start;
  gap: 16px;
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header .panel-title {
  margin-bottom: 0;
}

.kbd,
kbd {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 5px;
  padding: 1px 6px;
  color: #e2e8f0;
}

#hold-canvas,
#next-canvas {
  display: block;
  margin: 0 auto;
  background: #070b14;
  border: 1px solid #1e293b;
  border-radius: 10px;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-item {
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.stat-value {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.stat-value.accent {
  color: #38bdf8;
  font-size: 24px;
}

.stat-value.gold {
  color: var(--gold);
}

.key-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
  color: #cbd5e1;
}

.key-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.board-frame {
  position: relative;
  padding: 10px;
  background: linear-gradient(160deg, rgba(56, 189, 248, 0.22), rgba(99, 102, 241, 0.22));
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

#board-canvas {
  display: block;
  width: 300px;
  height: 600px;
  background: #050811;
  border-radius: 10px;
  border: 1px solid #1e293b;
}

.callout {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.6);
  color: #7dd3fc;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.35);
}

.overlay {
  position: absolute;
  inset: 10px;
  background: rgba(5, 8, 17, 0.84);
  backdrop-filter: blur(5px);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.overlay-card {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overlay-card h2 {
  font-size: 24px;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, #38bdf8, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-card p {
  font-size: 13px;
  line-height: 1.55;
  color: #cbd5e1;
}

.gameover-summary {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.summary-row strong {
  color: #38bdf8;
}

.submit-box {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.submit-box label {
  font-size: 12px;
  color: var(--muted);
}

.submit-row {
  display: flex;
  gap: 6px;
}

.submit-row input {
  flex: 1;
  min-width: 0;
  background: #070b14;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}

.submit-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.submit-status {
  font-size: 12px;
  min-height: 16px;
}

.submit-status.ok {
  color: var(--success);
}

.submit-status.err {
  color: var(--danger);
}

.overlay-actions {
  display: flex;
  justify-content: center;
}

.rank-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 330px;
  overflow-y: auto;
}

.rank-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid #1e293b;
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12px;
}

.rank-row.top1 {
  border-color: rgba(251, 191, 36, 0.5);
}

.rank-num {
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.rank-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.rank-score {
  font-weight: 700;
  color: #38bdf8;
  font-variant-numeric: tabular-nums;
}

.rank-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 18px 8px;
}

.touch-controls {
  display: none;
  width: 100%;
  max-width: 324px;
  flex-direction: column;
  gap: 8px;
}

.touch-row {
  display: flex;
  gap: 8px;
}

.tbtn {
  flex: 1;
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid #334155;
  color: var(--text);
  border-radius: 12px;
  padding: 14px 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.tbtn:active {
  background: #334155;
  transform: scale(0.96);
}

.tbtn-accent {
  background: rgba(6, 182, 212, 0.25);
  border-color: rgba(6, 182, 212, 0.6);
  color: #67e8f9;
}

.tbtn-wide {
  padding: 16px 8px;
  font-size: 18px;
}

.footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding-top: 4px;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .arena {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .board-col {
    order: 1;
    width: 100%;
  }

  .left-col {
    order: 2;
    width: 100%;
    max-width: 360px;
  }

  .right-col {
    order: 3;
    width: 100%;
    max-width: 360px;
  }

  .keys-panel {
    display: none;
  }

  .touch-controls {
    display: flex;
  }
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}
