:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  background: #ecefe9;
  color: #17211b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.app-header,
.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.app-header {
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2.2rem;
  line-height: 1.05;
}

.app-header p {
  margin-top: 6px;
  color: #526158;
}

.status-pill,
.section-title span {
  flex: 0 0 auto;
  border: 1px solid #c4cdc4;
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: #3c4a41;
  font-size: 0.9rem;
}

.top-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.input-workspace {
  margin-top: 16px;
}

.control-panel,
.result-panel,
.dice-panel,
.modifiers-section,
.tec-section,
.crt-section {
  border: 1px solid #cbd4cb;
  border-radius: 8px;
  background: #fff;
}

.control-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dice-panel {
  padding: 18px;
}

.dice-panel h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.result-panel h2,
.result-panel h3,
.crt-section h2 {
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.location-grid {
  display: grid;
  gap: 12px;
}

.defender-grid {
  display: grid;
  gap: 8px;
  border: 1px solid #d9cfc4;
  border-radius: 8px;
  padding: 12px;
  background: #faf7f2;
}

.location-card {
  border: 1px solid #d3ddd6;
  border-radius: 8px;
  padding: 12px;
  background: #f8faf8;
}

.location-head {
  display: grid;
  grid-template-columns: 110px repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.location-head h3 {
  align-self: center;
  font-size: 0.98rem;
}

.unit-table {
  display: grid;
  gap: 8px;
}

.unit-row {
  display: grid;
  grid-template-columns: 46px minmax(72px, 0.65fr) minmax(98px, 0.95fr) minmax(72px, 0.6fr) minmax(92px, 104px) minmax(68px, 0.6fr) repeat(5, minmax(48px, 0.42fr));
  gap: 8px;
  align-items: end;
}

.defender-unit {
  grid-template-columns: 46px minmax(72px, 120px) minmax(98px, 172px) minmax(72px, 110px) minmax(92px, 104px) minmax(68px, 88px) 78px minmax(88px, 120px) minmax(100px, 140px);
  justify-content: start;
}

.strength-field {
  max-width: 82px;
}

.unit-label {
  align-self: center;
  color: #526158;
  font-size: 0.86rem;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  color: #39483f;
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
button {
  min-height: 42px;
  border-radius: 6px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid #b9c5bb;
  padding: 8px 10px;
  background: #fff;
  color: #17211b;
}

input:disabled,
select:disabled {
  border-color: #d6ddd8;
  background: #edf0ed;
  color: #7b8780;
  cursor: not-allowed;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding-top: 22px;
}

.check-field input {
  width: 18px;
  min-height: 18px;
}

.mini-check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  color: #39483f;
  font-size: 0.82rem;
}

.mini-check input {
  width: 16px;
  min-height: 16px;
}

.dice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

button {
  border: 0;
  padding: 0 18px;
  background: #374c3f;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #25352b;
}

.secondary-button {
  width: 100%;
  margin-top: 12px;
  border: 1px solid #b9c5bb;
  background: #ffffff;
  color: #2d3d34;
}

.secondary-button:hover {
  background: #eef3ee;
}

.note {
  margin-top: 8px;
  color: #66746b;
  font-size: 0.86rem;
}

.result-panel {
  padding: 18px;
}

.result-list {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.result-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #e5eae5;
  padding-bottom: 8px;
}

dt {
  color: #526158;
}

dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.modifier-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: #39483f;
}

.modifiers-section {
  margin-top: 16px;
  padding: 18px;
}

.modifier-chart {
  max-width: 720px;
  border: 1px solid #87857a;
  padding: 14px 16px;
  background: #f2efe0;
}

.modifier-chart h3 {
  margin: 14px 0 8px;
  font-size: 0.98rem;
  font-style: italic;
}

.modifier-chart h3:first-child {
  margin-top: 0;
}

.modifier-chart ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 22px;
}

.modifier-chart p {
  margin-top: 12px;
}

.tec-section {
  margin-top: 16px;
  padding: 18px;
}

.tec-table-host {
  overflow-x: auto;
}

.tec-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;
}

.tec-table th,
.tec-table td {
  border: 1px solid #5d625e;
  padding: 8px 10px;
  text-align: center;
  vertical-align: middle;
}

.tec-table th {
  background: #e5e0b7;
  color: #111;
  font-weight: 700;
}

.tec-table td:first-child {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 10px;
  text-align: right;
}

.terrain-symbol {
  display: inline-block;
  width: 42px;
  height: 42px;
  border: 1px solid #222;
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.terrain-clear {
  background: #f7f3df;
}

.terrain-clear .terrain-symbol {
  background: #fff4dc;
}

.terrain-woods {
  background: #cce797;
}

.terrain-woods .terrain-symbol {
  background: #7ea46c;
}

.terrain-polder,
.terrain-polder-woods {
  background: #dbeff8;
}

.terrain-polder .terrain-symbol,
.terrain-polder-woods .terrain-symbol {
  background: #e8fbff;
}

.terrain-marsh {
  background: #cce0ee;
}

.terrain-marsh .terrain-symbol {
  background: #7bc3d0;
}

.terrain-town .terrain-symbol {
  background: #e7e2bf;
}

.terrain-city .terrain-symbol {
  background: #b2b49a;
}

.tec-table .terrain-woods td:nth-child(4),
.tec-table .terrain-marsh td:nth-child(4),
.tec-table .terrain-city td:nth-child(4) {
  font-weight: 700;
}

.crt-section {
  margin-top: 16px;
  padding: 18px;
  background: #c98d6d;
}

.odds-title {
  margin: -2px 0 8px;
  color: #fff7ef;
  font-size: 1rem;
  font-style: italic;
  font-weight: 700;
  text-align: center;
}

.crt-table-host {
  overflow-x: auto;
}

.crt-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  table-layout: fixed;
}

.crt-table th,
.crt-table td {
  border: 1px solid #cbd4cb;
  padding: 6px 8px;
  text-align: center;
}

.crt-table th {
  border-color: #333b3d;
  background: #c98d6d;
  color: #070707;
  font-size: 1rem;
}

.crt-table td {
  height: 42px;
  border-color: #6b7170;
  background: #f8f5df;
  font-size: 1.05rem;
}

.crt-table td strong,
.crt-table td span {
  display: block;
}

.crt-table td strong {
  line-height: 1.05;
}

.crt-table td span {
  margin-top: 2px;
  font-size: 0.72rem;
  font-style: italic;
  font-weight: 700;
}

.crt-table td.dd-drm {
  background: #f6d88d;
}

.crt-table td.full-retreat {
  background: #e8aa89;
}

.crt-table .is-active {
  outline: 3px solid #c6462f;
  outline-offset: -3px;
  color: #9b2818;
}

.crt-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: #23140e;
  font-size: 0.82rem;
  font-style: italic;
}

.legend-swatch {
  display: inline-block;
  width: 28px;
  height: 14px;
  border: 1px solid #7d583f;
  vertical-align: -2px;
}

.legend-swatch.dd-drm {
  background: #f6d88d;
}

.legend-swatch.full-retreat {
  background: #e8aa89;
}

@media (max-width: 860px) {
  .top-workspace {
    grid-template-columns: 1fr;
  }

  .location-head,
  .unit-row,
  .defender-unit {
    grid-template-columns: 1fr 1fr;
  }

  .unit-label,
  .location-head h3 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 14px;
  }

  .app-header,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .field-grid,
  .dice-row {
    grid-template-columns: 1fr;
  }

  .location-head,
  .unit-row,
  .defender-unit {
    grid-template-columns: 1fr;
  }

  .check-field {
    padding-top: 0;
  }

  .crt-legend {
    align-items: flex-start;
    flex-direction: column;
  }
}
