/* Tank Arena — 어두운 전술 콘솔 테마 */

:root {
  --bg: #0c0f13;
  --bg-2: #11161c;
  --panel: #161c24;
  --panel-2: #1b232c;
  --line: #263140;
  --line-soft: #1e2731;
  --text: #dfe6ee;
  --text-dim: #94a3b3;
  --text-faint: #64707e;
  --accent: #51cf66;
  --accent-dim: #2f9e44;
  --warn: #ffa94d;
  --danger: #ff6b6b;
  --info: #4dabf7;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

/* display 를 지정한 규칙이 hidden 속성을 덮지 않도록 한다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(1100px 500px at 15% -10%, rgba(81, 207, 102, .07), transparent 60%),
    radial-gradient(900px 450px at 100% 0%, rgba(77, 171, 247, .06), transparent 60%);
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 21px; }
p { margin: 0 0 .6em; }
hr { border: 0; border-top: 1px solid var(--line-soft); margin: 16px 0; }
a { color: var(--info); }

.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--text-dim); }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.gap { gap: 8px; }

/* ── 상단바 ─────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: rgba(12, 15, 19, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}

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

.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #2b8a3e);
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 2px 10px rgba(81,207,102,.25);
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; left: 5px; top: 11px;
  width: 16px; height: 7px; border-radius: 2px; background: #0c0f13; opacity: .65;
}

.brand-text { font-weight: 800; letter-spacing: .14em; font-size: 14px; }
.brand-text span { color: var(--accent); }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }

.nav-btn {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 7px 13px; border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600;
}
.nav-btn:hover { background: var(--panel); color: var(--text); }
.nav-btn.is-active { background: var(--panel-2); color: var(--accent); }

.user-area { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.user-badge {
  font-weight: 700; font-size: 13px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
}

/* ── 레이아웃 ───────────────────────────────────────── */

#main { max-width: 1480px; margin: 0 auto; padding: 22px 20px 60px; }

.view-head { margin-bottom: 16px; }
.view-head p { color: var(--text-dim); margin: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}

/* ── 버튼 / 폼 ──────────────────────────────────────── */

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover:not(:disabled) { background: #222c37; border-color: #33414f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  border-color: #2b8a3e; color: #07130b;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(180deg, var(--accent), var(--accent-dim)); }
.btn-danger { color: var(--danger); border-color: #4a2626; }
.btn.is-active { border-color: var(--accent); color: var(--accent); }

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

label { display: block; font-weight: 600; font-size: 13px; }
label .hint { color: var(--text-faint); font-weight: 400; margin-left: 4px; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  margin-top: 5px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(81,207,102,.13);
}
textarea { resize: vertical; }
select { margin-top: 0; width: auto; }

.inline-field {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; color: var(--text-dim);
}

.form-msg { min-height: 18px; font-size: 12.5px; color: var(--danger); margin: 0; }
.form-msg.ok { color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin-bottom: 14px; }
.tabs.tabs-sm { border: 0; margin-bottom: 8px; }
.tab {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 8px 12px; cursor: pointer; font: inherit; font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tabs-sm .tab { padding: 4px 10px; font-size: 12px; border-radius: 7px; border-bottom: 0; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs-sm .tab.is-active { background: var(--panel-2); border-bottom: 0; }

.badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim);
}
.badge.ok { color: var(--accent); border-color: #2b5c37; background: rgba(81,207,102,.1); }
.badge.bad { color: var(--danger); border-color: #5c2b2b; background: rgba(255,107,107,.1); }

/* ── 로그인 화면 ────────────────────────────────────── */

.auth-wrap {
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 34px;
  align-items: center; min-height: 68vh;
}
.auth-hero .lead { color: var(--text-dim); font-size: 15px; max-width: 46ch; }
.spec-list {
  list-style: none; padding: 0; margin: 20px 0 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px;
}
.spec-list li {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-left: 2px solid var(--accent-dim);
  border-radius: 7px; padding: 8px 12px; font-size: 13px; color: var(--text-dim);
}
.spec-list b { color: var(--text); }
.auth-card { max-width: 420px; width: 100%; }

/* ── 격납고 ─────────────────────────────────────────── */

.garage-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; }

.preview-card { display: flex; flex-direction: column; gap: 12px; }
#tank-preview {
  width: 100%; height: auto; border-radius: 8px;
  background:
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px,
    #0e1318;
  border: 1px solid var(--line-soft);
}
.preview-foot { display: flex; align-items: center; gap: 14px; }
.emblem-preview { width: 62px; height: 62px; flex: none; }
.emblem-preview svg { width: 100%; height: 100%; display: block; }
.preview-meta { display: flex; flex-direction: column; line-height: 1.35; }
.preview-meta span { color: var(--text-faint); font-size: 12px; }
.preview-foot .btn { margin-left: auto; }

.editor-card { align-self: start; }
.field { margin-bottom: 14px; }
.field-label {
  display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 7px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.swatch {
  width: 26px; height: 26px; border-radius: 7px; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset;
}
.swatch.is-active { border-color: #fff; }

.color-input {
  width: 46px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: var(--bg-2); cursor: pointer; margin: 0;
}

.shape-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.shape-btn {
  width: 62px; padding: 6px 4px 4px; border-radius: 9px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--text-dim);
}
.shape-btn svg { width: 32px; height: 32px; }
.shape-btn.is-active { border-color: var(--accent); color: var(--accent); background: rgba(81,207,102,.08); }

.icon-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px; max-height: 200px; overflow-y: auto; padding-right: 4px;
}
.icon-btn {
  aspect-ratio: 1; border-radius: 8px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 20px; font-weight: 700; color: var(--text);
}
.icon-btn.is-active { border-color: var(--accent); background: rgba(81,207,102,.12); }

/* ── 봇 공방 ────────────────────────────────────────── */

.workshop-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; align-items: start; }

.bot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bot-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent;
  background: var(--bg-2);
}
.bot-item:hover { border-color: var(--line); }
.bot-item.is-active { border-color: var(--accent); background: rgba(81,207,102,.08); }
.bot-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.bot-item.ok .dot { background: var(--accent); }
.bot-item .bi-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-item .bi-meta { margin-left: auto; font-size: 11px; color: var(--text-faint); flex: none; }

.bot-edit-card { display: flex; flex-direction: column; gap: 12px; }
.bot-edit-head { display: flex; align-items: center; gap: 10px; }
.bot-name-input {
  width: auto; flex: 1; margin: 0; font-size: 16px; font-weight: 700;
  background: transparent; border: 1px solid transparent; padding: 5px 8px;
}
.bot-name-input:hover { border-color: var(--line); }

.placeholder-card { display: grid; place-items: center; min-height: 220px; color: var(--text-faint); }

.code-area { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.code-head {
  display: flex; justify-content: space-between; padding: 6px 10px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--text-dim);
}
.code-wrap { display: flex; background: #0b0e12; max-height: 520px; }
.gutter {
  flex: none; padding: 10px 8px; text-align: right;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  color: var(--text-faint); background: #090c0f; user-select: none;
  border-right: 1px solid var(--line-soft); overflow: hidden;
  white-space: pre; width: 46px; flex: none; box-sizing: border-box;
}
#bot-source {
  flex: 1; min-width: 0; color: var(--text); margin: 0; border: 0; border-radius: 0; background: #0b0e12;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  padding: 10px 12px; min-height: 340px; max-height: 520px; resize: vertical;
  white-space: pre; overflow: auto;
}
#bot-source:focus { box-shadow: none; }

.compile-output {
  border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12px;
  background: #170f11; border: 1px solid #472328; color: #ffc9c9;
  max-height: 220px; overflow: auto; white-space: pre-wrap;
}
.compile-output.ok { background: #0f1711; border-color: #244a2c; color: #b2f2bb; }

/* ── 전장 ───────────────────────────────────────────── */

.arena-setup { display: flex; flex-direction: column; gap: 16px; }

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.slot {
  border: 1px dashed var(--line); border-radius: 9px; padding: 11px;
  min-height: 92px; display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-2); position: relative;
}
.slot.filled { border-style: solid; }
.slot .slot-no {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-faint); text-transform: uppercase;
}
.slot .slot-body { display: flex; align-items: center; gap: 9px; }
.slot .slot-emblem { width: 34px; height: 34px; flex: none; }
.slot .slot-emblem svg { width: 100%; height: 100%; display: block; }
.slot .slot-name { font-weight: 700; font-size: 13px; }
.slot .slot-owner { font-size: 11px; color: var(--text-faint); }
.slot .slot-remove {
  position: absolute; top: 6px; right: 6px;
  border: 0; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 6px;
}
.slot .slot-remove:hover { color: var(--danger); background: var(--panel); }
.slot .slot-empty { color: var(--text-faint); font-size: 12px; margin: auto; }

.roster-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.roster-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px;
}
.roster-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 9px;
  cursor: pointer;
}
.roster-item:hover { border-color: var(--line); }
.roster-item.is-picked { border-color: var(--accent); background: rgba(81,207,102,.08); }
.roster-item.disabled { opacity: .45; cursor: not-allowed; }
.roster-item .ri-emblem { width: 34px; height: 34px; flex: none; }
.roster-item .ri-emblem svg { width: 100%; height: 100%; display: block; }
.roster-item .ri-text { min-width: 0; }
.roster-item .ri-name { font-weight: 700; font-size: 13px; }
.roster-item .ri-desc {
  font-size: 11.5px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.battle { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.battle-main { display: flex; flex-direction: column; gap: 10px; }

#battlefield {
  /* 전장은 정사각형이므로, 열 너비와 화면 높이 중 작은 쪽에 맞춘다. */
  width: min(100%, 74vh); height: auto; aspect-ratio: 1;
  margin: 0 auto;
  background: #080b0e; border: 1px solid var(--line); border-radius: 10px;
  display: block;
}

.playback {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 9px; padding: 9px 11px;
}
.playback #pb-seek { flex: 1; min-width: 140px; accent-color: var(--accent); }
.speeds { display: flex; gap: 3px; }

.battle-side { display: flex; flex-direction: column; gap: 12px; }

.hud { display: flex; flex-direction: column; gap: 8px; }
.hud-tank {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-left: 3px solid var(--accent); border-radius: 9px; padding: 9px 11px;
}
.hud-tank.dead { opacity: .45; }
.hud-top { display: flex; align-items: center; gap: 8px; }
.hud-emblem { width: 26px; height: 26px; flex: none; }
.hud-emblem svg { width: 100%; height: 100%; display: block; }
.hud-name { font-weight: 700; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-hp-num { margin-left: auto; font-family: var(--mono); font-size: 12px; }
.bar { height: 6px; border-radius: 3px; background: #23303c; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 3px; transition: width .1s linear; }
.bar.hp > i { background: linear-gradient(90deg, #51cf66, #94d82d); }
.bar.hp.low > i { background: linear-gradient(90deg, #ff922b, #ff6b6b); }
.bar.boost > i { background: linear-gradient(90deg, #4dabf7, #74c0fc); }
.bar.reload { height: 4px; }
.bar.reload > i { background: linear-gradient(90deg, #9a6b12, #c79212); }
.bar.reload.ready > i { background: linear-gradient(90deg, #f59f00, #ffd43b); }
.hud-flags { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.flag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--panel-2); color: var(--text-faint); }
.flag.on { color: #07130b; background: var(--accent); }
.flag.warn { color: #1a1206; background: var(--warn); }

.result-card h3 { font-size: 15px; margin-bottom: 8px; }
.result-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 7px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 12.5px;
}
.result-row:last-child { border-bottom: 0; }
.result-row .place { width: 16px; flex: none; font-weight: 800; color: var(--text-faint); line-height: 1.6; }
.result-row.win .place { color: var(--accent); }
.result-row .r-emblem { width: 22px; height: 22px; flex: none; }
.result-row .r-emblem svg { width: 100%; height: 100%; display: block; }
.result-row .r-body { display: flex; flex-direction: column; min-width: 0; }
.result-row .r-name { font-weight: 700; }
.result-row .r-stats { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }

.log-card { max-height: 300px; display: flex; flex-direction: column; }
.event-log {
  list-style: none; margin: 0; padding: 0; overflow-y: auto;
  font-size: 12px; font-family: var(--mono); display: flex; flex-direction: column; gap: 2px;
}
.event-log li { color: var(--text-dim); }
.event-log li .t { color: var(--text-faint); }
.event-log li.hit { color: #ffc9c9; }
.event-log li.kill { color: var(--danger); font-weight: 700; }
.event-log li.boost { color: var(--info); }
.event-log li.msg { color: #d8b4fe; }
.event-log li.dq { color: var(--warn); font-weight: 700; }

/* ── 순위 ───────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.table td.num, .table th.num { text-align: right; font-family: var(--mono); }
.table .tb-emblem { width: 28px; height: 28px; }
.table .tb-emblem svg { width: 100%; height: 100%; display: block; }

.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.recent-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 8px;
  font-size: 12.5px; cursor: pointer;
}
.recent-item:hover { border-color: var(--line); }
.recent-item .ri-when { color: var(--text-faint); font-size: 11.5px; margin-left: auto; }

/* ── 교범 ───────────────────────────────────────────── */

.manual-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); gap: 16px; align-items: start; }
.doc {
  margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.6;
  /* 문서에 코드 예시가 섞여 있어 줄바꿈을 그대로 유지하고 가로로 스크롤한다. */
  white-space: pre; color: var(--text-dim); max-height: 560px; overflow: auto;
}

/* ── 토스트 ─────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 10px; font-weight: 600; z-index: 100;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.toast.bad { border-color: #5c2b2b; color: #ffc9c9; }
.toast.ok { border-color: #2b5c37; color: #b2f2bb; }

.spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,.25); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 반응형 ─────────────────────────────────────────── */

@media (max-width: 1180px) {
  .battle { grid-template-columns: 1fr; }
  .garage-grid { grid-template-columns: 1fr; }
  .workshop-grid { grid-template-columns: 1fr; }
  .auth-wrap { grid-template-columns: 1fr; padding-top: 10px; }
  .auth-card { max-width: none; }
  .manual-grid { grid-template-columns: 1fr; }
  #battlefield { width: 100%; }
}

@media (max-width: 700px) {
  #main { padding: 16px 14px 50px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .nav { order: 3; width: 100%; }
  .slots { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 24px; }
}
