:root {
  color-scheme: light;
  --bg: #eef1f3;
  --paper: #f8fbfb;
  --paper-2: #edf3f4;
  --ink: #171717;
  --muted: #5f6670;
  --line: #1f252b;
  --line-soft: #c9d1d6;
  --header: #6d2d25;
  --header-dark: #211612;
  --accent: #0f766e;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.app {
  min-height: 100vh;
  padding-bottom: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 12px 18px;
  color: #fff;
  background: var(--header-dark);
  border-bottom: 4px solid var(--header);
}

h1 {
  margin: 0 0 3px;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: #d9e0e5;
}

.status {
  color: #d9e0e5;
  font-size: 13px;
  white-space: nowrap;
}

.unit-card {
  max-width: 1120px;
  margin: 14px auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: visible;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.82), rgba(236,244,245,0.92)),
    var(--paper);
  box-shadow: 0 14px 30px rgba(10, 20, 28, 0.18);
}

.card-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 80px 112px;
  align-items: end;
  gap: 10px;
  padding: 8px 10px;
  color: #fff;
  background: linear-gradient(180deg, #7d352c, #522019);
}

label,
.line-label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.card-head label {
  color: #f4e9e6;
}

input,
select,
button {
  min-height: 34px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  padding: 5px 7px;
  font: inherit;
}

select,
input[type="number"] {
  border: 2px solid #4f5b64;
  background: linear-gradient(180deg, #ffffff, #eef3f5);
  cursor: pointer;
}

input[type="number"] {
  min-width: 56px;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  width: 22px;
  min-height: 28px;
  opacity: 1;
}

button {
  cursor: pointer;
}

input:focus,
select:focus,
button:focus,
.keyword-search:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.unit-name-field input {
  text-transform: uppercase;
  font-weight: 800;
}

.points-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  justify-self: stretch;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.points-box span {
  font-size: 14px;
  font-weight: 800;
}

#points {
  justify-self: end;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(82px, 1fr));
  border-top: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.stat-strip label {
  min-height: 54px;
  border-right: 1px solid var(--line);
  align-content: start;
  text-align: center;
}

.stat-strip label:last-child {
  border-right: 0;
}

.stat-strip span,
.weapon-grid span {
  display: block;
  padding: 5px 4px;
  color: #101418;
  font-weight: 900;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
}

.stat-strip input,
.stat-strip select {
  min-height: 30px;
  border: 0;
  text-align: center;
  font-weight: 700;
  background: transparent;
}

.split-input {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.split-input input:first-child {
  border-right: 1px solid var(--line);
}

.keyword-line,
.rule-line {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.line-label {
  color: #101418;
  padding-top: 6px;
}

.line-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.rule-line input {
  border-color: var(--line-soft);
}

.keyword-picker {
  position: relative;
  min-width: 0;
}

.selected-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 30px;
  padding: 3px;
  border: 2px dashed #8c9aa3;
  background: rgba(255, 255, 255, 0.78);
}

.selected-keywords:focus-within,
.keyword-picker:hover .selected-keywords {
  border-color: var(--accent);
  background: #fff;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 3px 7px;
  border: 1px solid #9da8af;
  background: #fff;
  font-size: 12px;
  font-style: italic;
}

.keyword-chip button {
  width: 18px;
  min-height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.keyword-search {
  margin-top: 4px;
  border: 2px solid #4f5b64;
  background: #fff;
}

.special-rules-inactive .selected-keywords,
.special-rules-inactive .keyword-search {
  opacity: 0.58;
  background: #eef1f3;
}

.special-rules-inactive .keyword-search {
  cursor: not-allowed;
}

.keyword-options {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: calc(100% + 3px);
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.keyword-option {
  display: block;
  width: 100%;
  min-height: 30px;
  padding: 6px 8px;
  border: 0;
  border-bottom: 1px solid #e4e8eb;
  text-align: left;
  background: #fff;
}

.keyword-option:hover {
  background: #edf3f4;
}

.weapon-card {
  border-top: 8px solid #050505;
}

.weapon-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  color: #fff;
  background: #050505;
}

.weapon-title {
  padding: 0;
  color: inherit;
  background: transparent;
  font-weight: 900;
}

.add-weapon-button {
  width: auto;
  min-height: 28px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.weapons-root {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.58);
}

.weapon-row {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
}

.weapon-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) 100px 80px minmax(260px, 2fr) 42px;
}

.weapon-grid label {
  min-height: 64px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.weapon-grid label:last-child {
  border-right: 0;
}

.weapon-grid input,
.weapon-grid select {
  border: 0;
  text-align: center;
  font-weight: 700;
  background: transparent;
}

.weapon-grid .keyword-picker {
  padding: 6px;
}

.weapon-grid .selected-keywords {
  min-height: 34px;
}

.weapon-grid .keyword-search {
  margin-top: 4px;
}

.weapon-grid .line-label {
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  font-weight: 900;
  text-align: center;
}

.weapon-actions {
  display: grid;
  align-items: stretch;
}

.remove-weapon-button {
  height: 100%;
  min-height: 64px;
  border: 0;
  background: #f4d8d4;
  color: #5e1d14;
  font-weight: 900;
  cursor: pointer;
}

.remove-weapon-button:disabled {
  background: #eceff1;
  color: #98a2ab;
  cursor: default;
}

.weapon-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 220px));
  gap: 10px;
  padding: 0 10px 10px;
}

.footer-box {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.footer-box output {
  display: grid;
  align-items: center;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.extras {
  display: grid;
  grid-template-columns: minmax(120px, 180px);
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line-soft);
}

.extras button {
  align-self: end;
  border-radius: 3px;
  cursor: pointer;
}

.advanced {
  padding: 0 10px 10px;
}

.army-panel,
.guide-panel {
  max-width: 1120px;
  margin: 14px auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 10px 22px rgba(10, 20, 28, 0.12);
}

.army-panel {
  overflow: hidden;
}

.army-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px minmax(420px, auto);
  gap: 10px;
  align-items: end;
  padding: 10px;
  background: #111820;
}

.army-head label,
.army-total {
  color: #edf3f4;
}

.army-total {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
}

.army-total output {
  display: grid;
  align-items: center;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  text-align: right;
}

.army-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(86px, 1fr));
  gap: 6px;
}

.army-actions button,
.extras button {
  border: 1px solid #33424d;
  background: #fff;
  font-weight: 800;
}

.army-list {
  display: grid;
  gap: 0;
}

.army-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.army-unit-card {
  margin: 10px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.84), rgba(238,244,245,0.92)),
    var(--paper);
  box-shadow: 0 6px 14px rgba(10, 20, 28, 0.12);
  font-size: 12px;
}

.army-unit-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 7px 9px;
  color: #fff;
  background: linear-gradient(180deg, #7d352c, #522019);
}

.army-unit-head strong {
  text-transform: uppercase;
  font-size: 15px;
}

.army-unit-head span {
  font-weight: 900;
  white-space: nowrap;
}

.army-stat-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(58px, 1fr));
  border-bottom: 1px solid var(--line);
}

.army-stat-strip div {
  display: grid;
  grid-template-rows: 24px 28px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.army-stat-strip div:last-child {
  border-right: 0;
}

.army-stat-strip span {
  display: grid;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  font-weight: 900;
}

.army-stat-strip strong {
  display: grid;
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
}

.army-keyword-line,
.army-rule-line {
  min-height: 28px;
  padding: 6px 9px;
  border-bottom: 1px solid var(--line-soft);
  text-align: center;
  font-style: italic;
  font-weight: 700;
}

.army-rule-line {
  text-align: left;
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
}

.army-weapon-title {
  padding: 6px 9px;
  color: #fff;
  background: #050505;
  font-weight: 900;
}

.army-weapon-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.army-weapon-table th,
.army-weapon-table td {
  padding: 6px 7px;
  border: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  overflow-wrap: anywhere;
}

.army-weapon-table th {
  background: rgba(255, 255, 255, 0.62);
  font-weight: 900;
  text-align: center;
}

.army-weapon-table td:nth-child(4),
.army-weapon-table td:nth-child(5),
.army-weapon-table td:nth-child(7),
.army-weapon-table td:nth-child(8) {
  text-align: center;
  font-weight: 800;
}

.army-row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.64);
}

.army-row-actions button {
  min-height: 28px;
  padding: 3px 6px;
  font-size: 12px;
  font-weight: 800;
}

.guide-panel {
  padding: 10px 12px;
}

.guide-panel summary {
  font-weight: 800;
  color: var(--ink);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  padding-top: 10px;
}

.guide-grid h2 {
  margin: 0 0 4px;
  font-size: 15px;
}

.guide-grid p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

dl {
  display: grid;
  grid-template-columns: max-content auto;
  gap: 7px 12px;
  margin: 10px 0 0;
  font-size: 13px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 700;
}

@media (max-width: 980px) {
  .unit-card {
    margin: 16px;
  }

  .army-panel,
  .guide-panel {
    margin: 16px;
  }

  .army-head {
    grid-template-columns: 1fr 120px;
  }

  .army-actions {
    grid-column: 1 / -1;
  }

  .army-unit-head {
    grid-template-columns: 1fr;
  }

  .army-unit-head span {
    white-space: normal;
  }

  .army-stat-strip {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
  }

  .army-weapon-table {
    font-size: 11px;
  }

  .card-head {
    grid-template-columns: 1fr 1fr;
  }

  .stat-strip {
    grid-template-columns: repeat(4, minmax(80px, 1fr));
  }

  .weapon-grid {
    grid-template-columns: 1fr 1fr;
  }

  .keyword-line,
  .rule-line {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-head,
  .extras {
    grid-template-columns: 1fr;
  }

  .stat-strip {
    grid-template-columns: repeat(2, minmax(80px, 1fr));
  }

  .weapon-grid {
    grid-template-columns: 1fr;
  }

  .weapon-footer {
    grid-template-columns: 1fr;
  }

  .army-head,
  .guide-grid {
    grid-template-columns: 1fr;
  }

  .army-actions {
    grid-template-columns: 1fr;
  }

  .army-stat-strip {
    grid-template-columns: repeat(2, minmax(58px, 1fr));
  }

  .army-weapon-table th,
  .army-weapon-table td {
    padding: 5px 4px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .unit-card,
  .guide-panel,
  .army-actions,
  .status {
    display: none !important;
  }

  .army-panel {
    box-shadow: none;
    border: 1px solid #000;
    margin: 0;
    max-width: none;
  }

  .army-head {
    grid-template-columns: 1fr 120px;
    color: #000;
    background: #fff;
    border-bottom: 2px solid #000;
  }

  .army-head input,
  .army-total output {
    border: 0;
    background: #fff;
    color: #000;
  }

  .army-unit-card {
    break-inside: avoid;
    box-shadow: none;
    margin: 8px 0;
  }

  .army-row-actions {
    display: none !important;
  }
}
