/* ============================================================
   Rally Mechanics Calculator — Stylesheet (dark theme)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #1a202c;
  --surface:     #2d3748;
  --surface2:    #3a4a5c;
  --border:      #4a5568;
  --text:        #e2e8f0;
  --muted:       #a0aec0;
  --blue:        #3182ce;
  --blue-light:  #63b3ed;
  --green:       #68d391;
  --orange:      #f6ad55;
  --red:         #fc8181;
  --yellow:      #ecc94b;

  --g-color:  #68d391;
  --a-color:  #63b3ed;
  --m-color:  #f6ad55;
  --s-color:  #fc8181;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 16px;
}

/* ── View system ──────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

.container {
  max-width: 960px;
  margin: 0 auto;
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  text-align: center;
  border-bottom: 2px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 1.8rem;
  color: var(--blue-light);
  letter-spacing: 0.04em;
}
.page-header h2 {
  font-size: 1.4rem;
  color: var(--blue-light);
}
.page-header .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── 5×5 Grid ─────────────────────────────────────────────── */
.grid-5x5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.grid-node {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.grid-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border-color: var(--blue-light);
}
.node-num {
  font-size: 1.3rem;
  font-weight: 700;
}
.node-status {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.node-empty   { border-color: var(--border); color: var(--muted); }
.node-partial { border-color: var(--orange); color: var(--orange); }
.node-ready   { border-color: var(--green);  color: var(--green);  }

/* Legend */
.legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 8px;
}
.legend-item {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.legend-item.empty   { color: var(--muted);  border-color: var(--border); }
.legend-item.partial { color: var(--orange); border-color: var(--orange); }
.legend-item.ready   { color: var(--green);  border-color: var(--green);  }

/* ── Buff grid ────────────────────────────────────────────── */
.buffs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.buff-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.buff-item label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

/* ── Form inputs ──────────────────────────────────────────── */
input[type="number"],
input[type="text"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input[type="number"]:focus,
select:focus {
  border-color: var(--blue-light);
}

/* ── Troop entries (settings) ─────────────────────────────── */
.troop-entry {
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.troop-header {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 14px;
  background: rgba(0,0,0,0.2);
  letter-spacing: 0.03em;
}
.troop-inputs {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  padding: 12px 14px;
}
.input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.input-row label {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Troop type colours */
.ground-color  { color: var(--g-color); }
.archer-color  { color: var(--a-color); }
.mounted-color { color: var(--m-color); }
.siege-color   { color: var(--s-color); }

/* ── Image upload ─────────────────────────────────────────── */
.upload-section {
  margin-bottom: 16px;
}
.upload-section label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="file"] {
  display: block;
  width: 100%;
  padding: 6px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}
input[type="file"]:hover { border-color: var(--blue-light); }

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.preview-thumb {
  max-width: 120px;
  max-height: 90px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
}

/* ── Enemy troop groups (scout) ───────────────────────────── */
.enemy-type-section {
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.enemy-type-header {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 14px;
  background: rgba(0,0,0,0.2);
}
.enemy-troop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.enemy-row-label {
  font-size: 0.82rem;
  color: var(--muted);
  min-width: 110px;
}
.enemy-row-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1;
}
.enemy-row-field select,
.enemy-row-field input {
  width: 100%;
}

/* ── Buttons ──────────────────────────────────────────────── */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 24px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover   { opacity: 0.85; }
.btn:active  { transform: scale(0.97); }

.btn-primary   { background: var(--blue);    color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--blue-light); border: 1px solid var(--blue-light); }
.btn-danger    { background: #742a2a;         color: var(--red);  border: 1px solid var(--red);  }
.btn-outline   { background: transparent;     color: var(--muted); border: 1px solid var(--border); }
.btn-small     { padding: 5px 12px; font-size: 0.8rem; background: var(--surface2); color: var(--blue-light); border: 1px solid var(--border); margin: 6px 14px 10px; }
.btn-icon      { padding: 4px 8px; font-size: 0.75rem; background: transparent; color: var(--red); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }

/* ── Report card ──────────────────────────────────────────── */
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}

.attack-sequence {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.attack-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  border: 1px solid var(--border);
}
.attack-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.attack-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.win-chance {
  text-align: center;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.win-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.win-value {
  font-size: 2.4rem;
  font-weight: 900;
}

.report-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.summary-box {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border);
}
.summary-box .summary-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.summary-box .summary-value {
  font-size: 1rem;
  font-weight: 700;
}

/* ── Battle log ───────────────────────────────────────────── */
.log-wave {
  margin-bottom: 18px;
  border-left: 4px solid var(--blue);
  padding-left: 14px;
}
.log-wave-title {
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.log-line {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.83rem;
  padding: 4px 8px;
  margin-bottom: 3px;
  border-radius: 4px;
}
.log-attack    { background: rgba(229,62,62,0.12);   color: #feb2b2; }
.log-retaliate { background: rgba(49,130,206,0.12);  color: #bee3f8; }
.log-wave-summary {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}
.log-final {
  font-size: 0.88rem;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 6px;
  margin-top: 12px;
  color: var(--text);
}

/* ── OCR status indicators ────────────────────────────────── */
.ocr-status       { font-size: 0.8rem; padding: 4px 0; min-height: 20px; }
.ocr-idle         { color: transparent; }
.ocr-loading      { color: var(--yellow); }
.ocr-ok           { color: var(--green); }
.ocr-error        { color: var(--red); }

/* Parsed troops list */
.parsed-row {
  padding: 5px 0;
  font-size: 0.88rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .grid-5x5        { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .grid-node       { padding: 10px 4px; }
  .node-num        { font-size: 1rem; }
  .buffs-grid      { grid-template-columns: 1fr; }
  .attack-sequence { grid-template-columns: 1fr; }
  .troop-inputs    { grid-template-columns: 1fr; }
  .report-summary  { grid-template-columns: 1fr; }
  .button-row      { flex-direction: column; }
  .btn             { width: 100%; text-align: center; }
}

/* ── Simulate bar (grid view) ─────────────────────────────── */
.simulate-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.config-count {
  font-size: 0.9rem;
  color: var(--muted);
}
.btn-large {
  padding: 12px 28px !important;
  font-size: 1rem !important;
  letter-spacing: 0.04em;
}

/* -- March cards (player settings) ──────────────────────────── */
.march-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.march-header {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.buff-inline-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.buff-small {
  width: 120px !important;
}
.parsed-inline-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 6px;
}
.parsed-row {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.parsed-total {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 600;
}

/* -- Alliance power grid ────────────────────────────────────── */
.alliance-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.alliance-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 8px;
}
.alliance-icon { font-size: 1.2rem; }
.alliance-name { font-weight: 700; font-size: 0.9rem; min-width: 80px; }
.alliance-stat { font-size: 0.9rem; flex: 1; }
.alliance-buff {
  font-size: 0.78rem;
  color: var(--green);
  background: rgba(104,211,145,0.1);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--green);
}

/* -- OCR status (re-used) ───────────────────────────────────── */
.parsed-inline { margin-top: 4px; }

/* ── iScope Navbar ───────────────────────────────────────────────────── */
.iscope-topbar {
  background: var(--surface, #1a1a2e);
  border-bottom: 1px solid var(--border, #2a2a4a);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 200;
}
.iscope-topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.iscope-topbar-logo img {
  height: 30px;
  border-radius: 6px;
}
.iscope-brand {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent, #f59e0b);
  letter-spacing: -0.5px;
}
.iscope-brand-sub {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted, #888);
  background: var(--surface2, #252540);
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--border, #2a2a4a);
  margin-left: 2px;
}
.iscope-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sub badge */
.nav-sub-badge {
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.nav-sub-active  { background: rgba(16,185,129,.15); color: #10b981; border: 1px solid rgba(16,185,129,.3); }
.nav-sub-inactive{ background: rgba(239,68,68,.15);  color: #ef4444; border: 1px solid rgba(239,68,68,.3);  }

/* Profile button */
.nav-profile {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border, #2a2a4a);
  background: var(--surface2, #252540);
  transition: background .2s;
  position: relative;
  user-select: none;
}
.nav-profile:hover { background: var(--surface3, #303058); }
.nav-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent, #f59e0b);
  color: #000;
  font-size: 0.7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-uname { font-size: 0.82rem; font-weight: 600; color: var(--text, #e2e8f0); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-caret  { font-size: 0.65rem; color: var(--muted, #888); }

/* Dropdown */
.nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 230px;
  background: var(--surface, #1a1a2e);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  z-index: 300;
  overflow: hidden;
}
.nav-dropdown.open { display: block; }
.nav-drop-info { padding: 12px 14px; }
.nav-drop-email{ font-size: 0.78rem; color: var(--muted, #888); margin-bottom: 4px; }
.nav-drop-sub  { font-size: 0.75rem; color: var(--text, #e2e8f0); }
.nav-drop-divider { height: 1px; background: var(--border, #2a2a4a); }
.nav-drop-item {
  display: block;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text, #e2e8f0);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
}
.nav-drop-item:hover { background: var(--surface2, #252540); }
.nav-drop-logout { color: #ef4444; }
.nav-login-btn {
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--accent, #f59e0b);
  color: #000;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  transition: opacity .2s;
}
.nav-login-btn:hover { opacity: .85; }

/* ── Auth Wall ───────────────────────────────────────────────────────── */
#auth-wall {
  position: fixed;
  inset: 0;
  background: var(--bg, #0f0f1a);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-wall-card {
  background: var(--surface, #1a1a2e);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.auth-wall-logo {
  height: 56px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.auth-wall-card h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent, #f59e0b);
  margin-bottom: 8px;
}
.auth-wall-card p {
  font-size: 0.88rem;
  color: var(--muted, #888);
  margin-bottom: 20px;
}
.auth-wall-btn {
  display: inline-block;
  padding: 10px 28px;
  border-radius: 20px;
  background: var(--accent, #f59e0b);
  color: #000;
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  transition: opacity .2s;
}
.auth-wall-btn:hover { opacity: .85; }
.auth-wall-hint {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--muted, #888);
}
.auth-wall-retry {
  background: none;
  border: none;
  color: var(--accent, #f59e0b);
  cursor: pointer;
  font-size: 0.78rem;
  text-decoration: underline;
  padding: 0;
}

/* Push app-content below navbar */
#app-content { display: block; }
