/* ClanWars — "TACTICAL FIELD MANUAL" theme.
   A light, squared, retro×modern DOSSIER look: manila paper, hard ink borders,
   offset block shadows, registration crop-marks, condensed stencil headers, and
   typewriter-monospace data. Two-ink accent system (signal orange + steel blue
   that mix to violet). Page modules build DOM with ui.el() and use these
   classes — restyling here re-skins the whole app. */
:root {
  /* ---- canvas: paper / manila ---- */
  --bg:          #ece6d8;
  --bg-2:        #e2dac8;
  --panel:       #f7f3ea;
  --panel-2:     #efe9da;
  --panel-3:     #e4dcc8;
  /* ---- ink ---- */
  --ink:         #16140f;
  --text:        #16140f;
  --muted:       #6f6755;
  --muted-2:     #97907d;
  --border:      #16140f;       /* HARD ink borders */
  --border-bright:#16140f;
  --border-soft: #c8bfa8;       /* hairline rule */
  /* ---- two-ink accent system ---- */
  --accent:      #e7501e;       /* signal orange (primary / actions) */
  --accent-2:    #b23f17;       /* burnt orange (hover) */
  --blue:        #1f3aa6;       /* steel blue (secondary ink / links) */
  --violet:      #6a37a8;       /* orange×blue overprint mix (special) */
  --olive:       #5d6336;
  --good:        #3f6f3a;
  --warn:        #b8860b;
  --danger:      #b22311;
  --attacker:    #b22311;
  --defender:    #3f6f3a;
  /* squared geometry + stamped shadows */
  --radius:      0px;
  --shadow:      6px 6px 0 rgba(22,20,15,.16);
  --shadow-hard: 4px 4px 0 var(--ink);
  --mono: "Space Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --sans: "Space Grotesk", system-ui, "Segoe UI", Roboto, sans-serif;
  --stencil: "Oswald", "Arial Narrow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* manila paper + faint engineering grid + warm corner tint */
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(22,20,15,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(22,20,15,.045) 1px, transparent 1px),
    radial-gradient(900px 420px at 100% -8%, rgba(231,80,30,.06) 0%, transparent 60%),
    radial-gradient(700px 380px at -8% 4%, rgba(31,58,166,.05) 0%, transparent 60%);
  background-size: 26px 26px, 26px 26px, 100% 100%, 100% 100%;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.1; font-family: var(--stencil); text-transform: uppercase; letter-spacing: .05em; }
h1 { font-size: 30px; } h2 { font-size: 21px; } h3 { font-size: 16px; }
p { line-height: 1.55; }

/* ---- layout ---- */
#app { max-width: 1100px; margin: 0 auto; padding: 22px 18px 90px; }
.container { max-width: 1100px; margin: 0 auto; }
.row { display: flex; gap: 14px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 14px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.grow { flex: 1; }
.gap { gap: 14px; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
/* dither checkerboard divider (retro graft) */
hr { border: none; height: 8px; margin: 18px 0; opacity: .22;
  background: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0) 0 0 / 8px 8px; }

/* SIGNATURE DEVICE: registration crop-marks on panel corners.
   Baked into .card so every card across every page inherits the look, plus a
   reusable .crop utility for other surfaces (hero, etc.). */
.crop { position: relative; }
.crop::before, .crop::after,
.card::before, .card::after {
  content: ""; position: absolute; width: 11px; height: 11px;
  border-color: var(--ink); border-style: solid; pointer-events: none;
}
.card::before, .crop::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.card::after,  .crop::after  { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

/* ---- nav: top-secret header strip ---- */
#nav { position: sticky; top: 0; z-index: 50; background: var(--ink); border-bottom: 3px solid var(--accent); }
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 4px; padding: 0 18px; height: 56px; }
.brand {
  font-family: var(--stencil); font-weight: 700; font-size: 20px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--bg);
  margin-right: 16px; display: flex; align-items: center; gap: 9px;
}
.brand:hover { text-decoration: none; }
.brand .logo { font-size: 20px; color: var(--accent); text-shadow: 2px 2px 0 var(--blue); }
.navlink {
  color: #cfc6b1; padding: 8px 13px; border-radius: 0;
  font-family: var(--stencil); font-weight: 600; font-size: 14px;
  text-transform: uppercase; letter-spacing: .07em; position: relative; border: 1px solid transparent;
}
.navlink:hover { color: #fff; background: rgba(255,255,255,.06); text-decoration: none; }
.navlink.active { color: var(--bg); }
.navlink.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 2px; height: 3px; background: var(--accent); }
.navlink.dev { color: var(--warn); }
.nav-spacer { flex: 1; }
.nav-badge {
  position: absolute; top: 0; right: 0; background: var(--accent); color: #fff;
  font-family: var(--mono); font-weight: 700; font-size: 10px; min-width: 16px; height: 16px;
  border-radius: 0; display: grid; place-items: center; padding: 0 3px;
}

/* ---- cards: paper dossier panels ---- */
.card { position: relative; background: var(--panel); border: 2px solid var(--border); border-radius: 0; padding: 18px; box-shadow: var(--shadow); }
.card.pad-lg { padding: 24px; }
.card.hover { transition: .12s; cursor: pointer; }
.card.hover:hover { transform: translate(-2px,-2px); box-shadow: 8px 8px 0 rgba(22,20,15,.2); }
.card-title { font-family: var(--stencil); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; font-size: 15px; margin-bottom: 3px; }

/* section eyebrow: stamped label */
.eyebrow { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.eyebrow::before { content: "■"; color: var(--accent); }

/* document chrome: doc-bar + rank cell + classified stamp */
.doc-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--ink); padding-bottom: 8px; margin-bottom: 14px; }
.rank { font-family: var(--stencil); font-weight: 700; font-size: 18px; min-width: 30px; text-align: center; color: var(--ink); border-right: 2px solid var(--ink); padding-right: 8px; }
.rank.top { color: var(--accent); }

/* ---- buttons: stamped tactical keys (press-into-shadow) ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel); color: var(--ink); border: 2px solid var(--ink); border-radius: 0;
  padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer;
  font-family: var(--stencil); text-transform: uppercase; letter-spacing: .07em;
  transition: transform .07s, box-shadow .07s, background .12s, color .12s;
  user-select: none; box-shadow: 3px 3px 0 var(--ink);
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px,3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: 3px 3px 0 var(--ink); transform: none; }
.btn.primary { background: var(--accent); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--panel); border-color: var(--danger); color: var(--danger); box-shadow: 3px 3px 0 var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.danger:active { box-shadow: 0 0 0 var(--danger); }
.btn.good { background: var(--good); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border-soft); color: var(--muted); box-shadow: none; }
.btn.ghost:hover { color: var(--ink); border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 11px; box-shadow: 2px 2px 0 currentColor; }
.btn.sm:hover { box-shadow: 3px 3px 0 currentColor; }
.btn.sm:active { box-shadow: 0 0 0 currentColor; }
.btn.ghost.sm { box-shadow: none; }
.btn.ghost.sm:hover { box-shadow: 2px 2px 0 var(--ink); }
.btn.lg { padding: 13px 24px; font-size: 16px; }
.btn.block { width: 100%; }
/* selected / controller-focused menu item — wins over .btn.ghost(.sm) (declared later + higher specificity) */
.btn.selected, .btn.ghost.selected, .btn.ghost.sm.selected,
.btn.is-focused, .btn.ghost.is-focused, .btn.ghost.sm.is-focused {
  background: var(--accent); border-color: var(--ink); color: #fff;
  box-shadow: 3px 3px 0 var(--ink); outline: 2px solid var(--ink); outline-offset: 2px;
}
.btn.selected .muted, .btn.selected .tiny, .btn.is-focused .muted, .btn.is-focused .tiny { color: #fff; }

/* ---- gamepad navigation cursor: a bold accent ring on the focused control
   (shown only while navigating the site with a controller) ---- */
.gp-focus {
  outline: 3px solid var(--accent) !important;
  outline-offset: 3px;
  box-shadow: 4px 4px 0 var(--accent) !important;
  position: relative; z-index: 5;
}

/* ---- forms: typed intake form ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }
.input, .textarea, select { background: #fffdf7; color: var(--ink); border: 2px solid var(--ink); border-radius: 0; padding: 10px 12px; font-size: 14px; font-family: var(--mono); width: 100%; }
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 3px 3px 0 var(--accent); }
.textarea { min-height: 92px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=color] { padding: 2px; height: 40px; width: 56px; cursor: pointer; border: 2px solid var(--ink); }
.error-text { color: var(--danger); font-size: 13px; font-family: var(--mono); }

/* ---- badges / tags / pills: classified stamps ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 0; background: transparent; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; border: 1.5px solid var(--muted); }
.badge.good   { color: var(--good);   border-color: var(--good); }
.badge.warn   { color: var(--warn);   border-color: var(--warn); }
.badge.danger { color: var(--danger); border-color: var(--danger); }
.badge.accent { background: var(--accent); color: #fff; border-color: var(--ink); }
.badge.stamp  { transform: rotate(-5deg); border-width: 2px; padding: 4px 10px; font-size: 12px; }
.tag { font-family: var(--mono); font-weight: 700; font-size: 12px; padding: 1px 7px; border-radius: 0; background: var(--ink); color: var(--bg); border: none; letter-spacing: .04em; }
.pill { padding: 6px 14px; border-radius: 0; background: var(--panel); border: 2px solid var(--ink); font-family: var(--mono); font-size: 12px; font-weight: 700; cursor: pointer; text-transform: uppercase; letter-spacing: .06em; }
.pill.active { background: var(--ink); color: var(--bg); }

/* ---- avatar: dossier photo chip ---- */
.avatar { width: 40px; height: 40px; border-radius: 0; display: grid; place-items: center; font-family: var(--stencil); font-weight: 700; color: #fff; flex: none; font-size: 15px; border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; box-shadow: 1.5px 1.5px 0 var(--ink); }
.avatar.lg { width: 66px; height: 66px; font-size: 28px; box-shadow: 3px 3px 0 var(--ink); }

/* ---- stat blocks: typed readouts ---- */
.stat { background: var(--panel-2); border: 2px solid var(--ink); border-radius: 0; padding: 12px 14px; min-width: 92px; position: relative; }
.stat::after { content: ""; position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; background: var(--accent); }
.stat .num { font-size: 26px; font-weight: 700; font-family: var(--mono); line-height: 1; }
.stat .lbl { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .16em; margin-top: 5px; }
/* .bare = a stat used inline (e.g. a leaderboard "power" figure): no box/tick */
.stat.bare { border: none; background: none; padding: 0; box-shadow: none; min-width: auto; }
.stat.bare::after { content: none; }

/* ---- lists / tables: ledger rows ---- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-bottom: 1px dashed var(--border-soft); }
.list-item:last-child { border-bottom: none; }
.list-item.click { cursor: pointer; transition: .1s; }
.list-item.click:hover { background: var(--panel-2); box-shadow: inset 4px 0 0 var(--accent); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; font-family: var(--mono); }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-soft); }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .14em; border-bottom: 2px solid var(--ink); }
.table tr:hover td { background: var(--panel-2); }

/* ---- tabs: file-folder index ---- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--ink); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 8px 16px; cursor: pointer; color: var(--muted); font-family: var(--stencil); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: .07em; border: 2px solid transparent; border-bottom: none; margin-bottom: -2px; background: transparent; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); background: var(--panel); border-color: var(--ink); }

/* ---- misc ---- */
.empty { text-align: center; color: var(--muted); padding: 44px 20px; border: 2px dashed var(--border-soft); background: repeating-linear-gradient(45deg, transparent, transparent 9px, rgba(22,20,15,.025) 9px, rgba(22,20,15,.025) 18px); }
.empty .big { font-size: 40px; opacity: .6; margin-bottom: 8px; filter: grayscale(.4); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.loading { display: grid; place-items: center; padding: 80px; }
@keyframes spin { to { transform: rotate(360deg); } }

.hp-bar { height: 9px; background: var(--panel-3); border: 1.5px solid var(--ink); border-radius: 0; overflow: hidden; }
.hp-bar > i { display: block; height: 100%; background: var(--good); }

/* ---- toasts ---- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--panel); border: 2px solid var(--ink); border-left: 6px solid var(--accent); border-radius: 0; padding: 12px 16px; box-shadow: var(--shadow); font-family: var(--mono); font-size: 13px; animation: slidein .25s ease; max-width: 340px; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--good); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }

/* ---- modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(22,20,15,.55); display: grid; place-items: center; z-index: 150; padding: 20px; }
.modal { position: relative; background: var(--panel); border: 2px solid var(--ink); border-radius: 0; padding: 24px; max-width: 460px; width: 100%; box-shadow: var(--shadow); }
.modal::before, .modal::after { content: ""; position: absolute; width: 11px; height: 11px; border-color: var(--ink); border-style: solid; pointer-events: none; }
.modal::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.modal::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

/* ---- hero: classified briefing masthead ---- */
.hero { position: relative; padding: 30px 26px 26px; background: var(--panel); border: 2px solid var(--ink); box-shadow: var(--shadow); overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(135deg, transparent, transparent 30px, rgba(231,80,30,.05) 30px, rgba(231,80,30,.05) 32px); }
.hero h1 { font-size: 46px; color: var(--ink); position: relative; }
.hero h1 .hl { color: var(--violet); }   /* orange×blue overprint highlight */
.hero p { color: var(--muted); font-size: 16px; max-width: 640px; position: relative; }

/* ---- editor + game (used by editor.js / play.js) ---- */
.editor-wrap { display: grid; grid-template-columns: 230px 1fr; gap: 14px; }
.editor-canvas-wrap, .game-wrap { background: #11100c; border: 2px solid var(--ink); border-radius: 0; overflow: hidden; position: relative; box-shadow: var(--shadow); }
.editor-canvas-wrap canvas, .game-wrap canvas { display: block; cursor: crosshair; image-rendering: pixelated; }
.palette { display: flex; flex-direction: column; gap: 5px; max-height: 70vh; overflow: auto; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 7px; border-radius: 0; border: 2px solid transparent; cursor: pointer; font-family: var(--mono); font-size: 13px; }
.palette-item:hover { background: var(--panel-2); }
.palette-item.active { border-color: var(--ink); background: var(--panel-2); box-shadow: 2px 2px 0 var(--ink); }
.swatch { width: 22px; height: 22px; border-radius: 0; border: 2px solid var(--ink); flex: none; }
.hud { position: absolute; pointer-events: none; padding: 12px; inset: 0; display: flex; flex-direction: column; justify-content: space-between; }
.hud .topbar, .hud .botbar { display: flex; justify-content: space-between; align-items: flex-start; }
.hud .panel { background: var(--panel); border: 2px solid var(--ink); border-radius: 0; padding: 8px 12px; pointer-events: auto; box-shadow: 2px 2px 0 var(--ink); }
.scoreboard { font-family: var(--mono); font-size: 13px; }

@media (max-width: 820px) {
  .grid.two { grid-template-columns: 1fr; }
  .editor-wrap { grid-template-columns: 1fr; }
  .nav-inner { flex-wrap: wrap; height: auto; padding: 8px 18px; }
  .hero h1 { font-size: 34px; }
}
