/* Age of War — TechTools tool styles. Mobile-first, dark, amber/era accents. */
:root {
  --tt-topnav-h: 64px; /* seed; navbar publishes the real value at runtime */
  --bg: #0c1118;
  --bg2: #121a24;
  --panel: #18222e;
  --panel2: #1f2c3a;
  --border: rgba(255, 255, 255, 0.10);
  --border2: rgba(255, 255, 255, 0.18);
  --text: #eef3f8;
  --muted: rgba(238, 243, 248, 0.62);
  --gold: #f5b942;
  --gold2: #e08a2b;
  --me: #49b6ff;
  --enemy: #ff5b5b;
  --green: #5fdd6a;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #16263a 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

.aow-app { width: 100%; }
.screen.hidden, .hidden { display: none !important; }

/* ===================== MENU ===================== */
#screen-menu {
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.6rem) 1rem 3rem;
}
.aow-hero { text-align: center; margin-bottom: clamp(1.4rem, 5vw, 2.6rem); }
.aow-title {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(180deg, #ffe6a8 0%, var(--gold) 45%, var(--gold2) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 24px rgba(224, 138, 43, 0.25);
}
.aow-sub { color: var(--muted); font-size: clamp(0.95rem, 2.6vw, 1.15rem); margin-top: 0.7rem; max-width: 40ch; margin-inline: auto; }

.aow-modes { display: grid; grid-template-columns: 1fr; gap: 1.1rem; }
@media (min-width: 760px) { .aow-modes { grid-template-columns: 1fr 1fr; } }

.mode-card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem;
  box-shadow: var(--shadow);
}
.mode-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.mode-head i { font-size: 1.4rem; color: var(--gold); width: 1.6rem; text-align: center; }
.mode-head h2 { font-size: 1.3rem; font-weight: 700; }
.mode-desc { color: var(--muted); font-size: 0.92rem; margin-bottom: 1rem; }

.diff-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.diff-btn {
  padding: 0.85rem 0.5rem; border-radius: 10px; cursor: pointer;
  background: var(--panel2); color: var(--text); border: 1px solid var(--border2);
  font-weight: 600; font-size: 0.98rem; transition: transform .12s, background .12s, border-color .12s;
}
.diff-btn:hover { background: #283747; transform: translateY(-2px); border-color: var(--gold); }
.diff-btn.danger:hover { border-color: var(--enemy); }
.sp-stats { margin-top: 0.9rem; color: var(--muted); font-size: 0.85rem; text-align: center; min-height: 1.2em; }

.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.aow-input {
  width: 100%; padding: 0.75rem 0.85rem; border-radius: 10px;
  background: #0e1620; border: 1px solid var(--border2); color: var(--text);
  font-size: 1rem; font-family: inherit;
}
.aow-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245, 185, 66, 0.15); }
.aow-input.code { text-transform: uppercase; letter-spacing: 0.25em; text-align: center; font-weight: 700; }

.big-btn {
  width: 100%; margin-top: 0.8rem; padding: 0.85rem 1rem; border-radius: 10px; cursor: pointer;
  background: var(--panel2); color: var(--text); border: 1px solid var(--border2);
  font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  transition: transform .12s, filter .12s, background .12s;
}
.big-btn:hover { transform: translateY(-2px); background: #283747; }
.big-btn.primary { background: linear-gradient(135deg, var(--gold) 0%, var(--gold2) 100%); color: #2a1c05; border: none; }
.big-btn.primary:hover { filter: brightness(1.07); }
.big-btn.ghost { background: transparent; }
.room-row { margin-top: 0.6rem; }
.join-group { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.join-group .aow-input { flex: 1; }
.join-group .big-btn { width: auto; margin: 0; padding-inline: 1.1rem; }

.aow-howto {
  max-width: 1040px; margin: 1.6rem auto 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.4rem 1.1rem;
}
.aow-howto summary { cursor: pointer; padding: 0.7rem 0; font-weight: 600; color: var(--gold); }
.aow-howto ul { margin: 0.3rem 0 0.9rem 1.2rem; color: var(--muted); font-size: 0.9rem; line-height: 1.8; }

/* ===================== LOBBY ===================== */
.screen.overlay {
  position: fixed; inset: 0; z-index: calc(var(--tt-z-modal, 1000) + 5);
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 15, 0.86); backdrop-filter: blur(4px); padding: 1rem;
}
.lobby-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem 1.6rem; text-align: center; max-width: 380px; width: 100%; box-shadow: var(--shadow);
}
.spinner {
  width: 46px; height: 46px; margin: 0 auto 1.1rem; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.14); border-top-color: var(--gold); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.lobby-status { color: var(--text); font-size: 1.02rem; margin-bottom: 0.8rem; }
.lobby-code {
  font-family: 'Cinzel', serif; font-weight: 900; font-size: 2.4rem; letter-spacing: 0.3em;
  color: var(--gold); background: #0e1620; border: 1px dashed var(--gold2); border-radius: 10px;
  padding: 0.6rem 0.4rem 0.6rem 0.7rem; margin-bottom: 0.9rem;
}

/* ===================== GAME ===================== */
.screen.game:not(.hidden) {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--tt-topnav-h, 64px));
  height: calc(100dvh - var(--tt-topnav-h, 64px));
  overflow: hidden;
}
.hud-top {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.7rem;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.hud-side { display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 0; }
.hud-side.opp { justify-content: flex-end; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hud-age { font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 8.5rem; }
.hud-gold { font-weight: 700; color: var(--gold); white-space: nowrap; }
.hud-gold i { margin-right: 2px; }
.hud-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.sudden { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; min-height: 0.8em; }
.sudden.warn { color: var(--gold); }
.sudden.on { color: var(--enemy); animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { opacity: 0.45; } }
.hud-oppname { font-weight: 600; max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-ping { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border2);
  background: var(--panel2); color: var(--text); cursor: pointer; flex: 0 0 auto;
}
.icon-btn:hover { background: #2b3b4c; }
.icon-btn.danger:hover { background: #5a2530; border-color: var(--enemy); }

.bases-bar { display: flex; gap: 0.5rem; padding: 0.35rem 0.7rem; background: var(--bg); flex: 0 0 auto; }
.base-meter { display: flex; align-items: center; gap: 0.4rem; flex: 1; }
.base-meter.opp { flex-direction: row; justify-content: flex-end; }
.bm-label { font-size: 0.9rem; }
.base-meter.mine .bm-label { color: var(--me); }
.base-meter.opp .bm-label { color: var(--enemy); }
.bm-track { flex: 1; height: 12px; background: #0a0f16; border-radius: 7px; overflow: hidden; border: 1px solid var(--border); }
.bm-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #2f8fe0, var(--me)); transition: width .2s; }
.bm-fill.enemy { background: linear-gradient(90deg, var(--enemy), #b52f2f); }
.base-meter.opp .bm-track { transform: scaleX(-1); }
.bm-hp { font-size: 0.74rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.6rem; }
.base-meter.opp .bm-hp { text-align: right; }

.battlefield { position: relative; flex: 1 1 auto; min-height: 0; background: #0a0f16; }
#cv { display: block; width: 100%; height: 100%; touch-action: none; }
.field-msg {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(8, 12, 18, 0.85); border: 1px solid var(--border2); border-radius: 10px;
  padding: 0.7rem 1.1rem; font-weight: 600; text-align: center; pointer-events: none;
}
.field-msg.paused { font-size: 1.4rem; color: var(--gold); }

/* ----- controls ----- */
.controls { flex: 0 0 auto; background: var(--bg2); border-top: 1px solid var(--border); padding: 0.5rem 0.6rem 0.7rem; }
.xp-bar { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.xp-track { flex: 1; height: 10px; background: #0a0f16; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.xp-fill { height: 100%; width: 0; background: linear-gradient(90deg, #8a6bff, #c0a0ff); transition: width .2s; }
.xp-text { font-size: 0.74rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.xp-text i { color: #c0a0ff; }

.control-row { display: flex; gap: 0.6rem; align-items: stretch; flex-wrap: wrap; }
.unit-bar { display: flex; gap: 0.5rem; flex: 1 1 280px; min-width: 0; }
.unit-btn {
  position: relative; flex: 1; min-width: 0; cursor: pointer; color: var(--text);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--border2); border-left: 4px solid var(--uc, var(--gold));
  border-radius: 10px; padding: 0.5rem 0.45rem; display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .1s, background .1s; min-height: 64px; justify-content: center;
}
.unit-btn:hover { background: #2b3b4c; transform: translateY(-2px); }
.unit-btn.cant { opacity: 0.42; }
.unit-btn:active { transform: scale(0.96); }
.ub-key { position: absolute; top: 3px; left: 5px; font-size: 0.6rem; color: var(--muted); border: 1px solid var(--border2); border-radius: 4px; padding: 0 3px; }
.ub-icon { font-size: 1rem; color: var(--uc, var(--gold)); }
.ub-icon.r { color: #7ec0ff; }
.ub-icon.e { color: var(--gold); }
.ub-name { font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.05; max-width: 100%; overflow: hidden; }
.ub-cost { font-size: 0.74rem; font-weight: 700; color: var(--gold); }
.ub-cost i { font-size: 0.62rem; }

.action-bar { display: flex; gap: 0.5rem; align-items: stretch; flex: 1 1 320px; min-width: 0; }
.act-btn {
  cursor: pointer; color: var(--text); background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--border2); border-radius: 10px; padding: 0.5rem 0.7rem;
  display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; font-size: 0.82rem; white-space: nowrap;
  transition: transform .1s, filter .1s; position: relative;
}
.act-btn kbd { font-size: 0.58rem; color: var(--muted); border: 1px solid var(--border2); border-radius: 4px; padding: 0 3px; margin-left: 2px; }
.act-btn:disabled { opacity: 0.45; cursor: default; }
.act-btn.evolve { background: linear-gradient(135deg, #6a4bd0, #8a6bff); border: none; color: #fff; flex: 0 0 auto; }
.act-btn.evolve.ready { animation: glow 1s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 14px rgba(138, 107, 255, 0.8); } }
.act-btn.special { background: linear-gradient(135deg, var(--gold2), #b5491f); border: none; color: #fff; flex: 1; justify-content: center; }
.act-btn.special:disabled { background: #2a3543; color: var(--muted); }
.act-btn.special.ready { box-shadow: 0 0 12px rgba(245, 185, 66, 0.5); }
.sp-label { display: flex; flex-direction: column; line-height: 1.05; align-items: flex-start; }
.sp-cd { font-size: 0.62rem; opacity: 0.85; font-variant-numeric: tabular-nums; }
.queue-chip { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; color: var(--muted); padding: 0 0.4rem; }

.turret-slots { display: flex; gap: 0.35rem; }
.slot-btn {
  width: 46px; cursor: pointer; border-radius: 9px; border: 1px solid var(--border2);
  background: var(--panel); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 0.62rem;
}
.slot-btn .sl-top { font-size: 0.95rem; }
.slot-btn .sl-cost { font-size: 0.6rem; color: var(--gold); font-weight: 700; }
.slot-btn.locked { opacity: 0.7; border-style: dashed; }
.slot-btn.locked .sl-top { color: var(--muted); }
.slot-btn.empty .sl-top { color: var(--green); }
.slot-btn.filled { background: linear-gradient(180deg, #2c3a30, #1d2a22); border-color: #3c5a44; }
.slot-btn.filled .sl-top { color: var(--green); }
.slot-btn:hover { transform: translateY(-2px); }

/* ----- result ----- */
.result {
  position: absolute; inset: 0; z-index: calc(var(--tt-z-modal, 1000) + 6);
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 15, 0.84); backdrop-filter: blur(3px); padding: 1rem;
}
.result-card {
  background: var(--panel); border: 1px solid var(--border2); border-radius: var(--radius);
  padding: 1.8rem 1.6rem; text-align: center; max-width: 420px; width: 100%; box-shadow: var(--shadow);
}
.result-card h2 { font-family: 'Cinzel', serif; font-size: 2.2rem; margin-bottom: 0.5rem; }
.result.win .result-card h2 { color: var(--green); }
.result.loss .result-card h2 { color: var(--enemy); }
.result.draw .result-card h2 { color: var(--gold); }
.result-card p { color: var(--muted); margin-bottom: 0.4rem; }
.result-stats { font-size: 0.85rem; color: var(--text); margin-bottom: 1.1rem; }
.result-actions { display: flex; gap: 0.6rem; }
.result-actions .big-btn { margin: 0; }

/* ----- toast ----- */
.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(120%);
  background: #2a1c05; color: #ffe6a8; border: 1px solid var(--gold2); border-radius: 10px;
  padding: 0.7rem 1.1rem; font-weight: 600; z-index: calc(var(--tt-z-toast, 1100) + 10);
  transition: transform .25s; max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===================== responsive ===================== */
@media (max-width: 560px) {
  .control-row { flex-direction: column; }
  .unit-bar, .action-bar { flex: 1 1 auto; }
  .ub-name { font-size: 0.66rem; }
  .hud-age { max-width: 5.4rem; font-size: 0.74rem; }
  .hud-oppname { max-width: 4.5rem; }
  .turret-slots { flex: 1; }
  .slot-btn { flex: 1; width: auto; min-height: 44px; }
  .act-btn.evolve span { display: none; }
  .diff-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .ub-cost { font-size: 0.68rem; }
  .act-btn kbd, .ub-key { display: none; }
}

/* mute toggle */
.icon-btn.muted { color: var(--enemy); }

/* rotate hint — only on portrait phones (this is a landscape-first game) */
.rotate-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: none; align-items: center; gap: 6px;
  background: rgba(8, 12, 18, 0.82); border: 1px solid var(--border2); border-radius: 20px;
  padding: 6px 14px; font-size: 0.78rem; color: var(--muted); pointer-events: none; white-space: nowrap;
}
@media (max-width: 600px) and (orientation: portrait) {
  .rotate-hint { display: inline-flex; animation: rhpulse 2.4s ease-in-out infinite; }
}
@keyframes rhpulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* landscape phones / short viewports: compact the chrome so the battlefield
   keeps enough height, and keep the controls in a single row */
@media (max-height: 500px) and (orientation: landscape) {
  .hud-top { padding: 0.2rem 0.6rem; }
  .bases-bar { padding: 0.18rem 0.6rem; }
  .controls { padding: 0.3rem 0.55rem 0.4rem; }
  .control-row { flex-direction: row; }
  .xp-bar { margin-bottom: 0.3rem; }
  .unit-btn { min-height: 46px; }
  .battlefield { min-height: 110px; }
  .slot-btn { width: 40px; }
}
