* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #1a1a1a;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  position: relative;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.app-header-text {
  flex: 1;
  min-width: 0;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.hint {
  margin: 0;
  color: #555;
  font-size: 0.9rem;
  line-height: 1.45;
}

.app-header-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}

.lang-btn {
  margin: 0;
  padding: 0.35rem 0.65rem;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  line-height: 1;
}

.lang-btn + .lang-btn {
  border-left: 1px solid #cbd5e1;
}

.lang-btn:hover {
  background: #f1f5f9;
  color: #334155;
}

.lang-btn.is-active {
  background: #2563eb;
  color: #fff;
}

.lang-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
  z-index: 1;
}

.header-icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.help-btn {
  background: #64748b;
}

.help-btn:hover {
  background: #475569;
}

.why-btn {
  background: #dc2626;
}

.why-btn:hover {
  background: #b91c1c;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: #0f766e;
}

.back-btn:hover {
  background: #0d9488;
}

.back-btn-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.header-icon-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.help-dialog {
  border: none;
  padding: 0;
  max-width: calc(100vw - 2rem);
  width: min(520px, 100%);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.help-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.help-dialog-inner {
  position: relative;
  padding: 1.25rem 1.35rem 1.35rem;
  max-height: min(80vh, 640px);
  overflow-y: auto;
}

.help-dialog-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  color: #64748b;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.help-dialog-close:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.help-dialog h2 {
  margin: 0 2rem 0.75rem 0;
  font-size: 1.2rem;
}

.help-dialog h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
  color: #334155;
}

.help-dialog ul {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #444;
}

.help-dialog li {
  margin-bottom: 0.35rem;
}

.why-dialog-lead {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #334155;
}

.why-stats-table {
  width: 100%;
  margin: 0.75rem 0 1rem;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.why-stats-table th,
.why-stats-table td {
  padding: 0.45rem 0.55rem;
  border: 1px solid #e2e8f0;
  text-align: center;
}

.why-stats-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
}

.why-stats-table td:first-child {
  text-align: left;
  font-weight: 500;
}

.help-dialog p {
  margin: 0.5rem 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #444;
}

.panel {
  background: #fff;
  border: 1px solid #dde2e8;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
}

.inputs.sides {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
}

label > span:first-child {
  color: #444;
  font-weight: 600;
}

input[type="text"] {
  padding: 0.55rem 0.65rem;
  border: 1px solid #c5ccd6;
  border-radius: 6px;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  text-align: center;
}

input[type="text"]:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
  border-color: #3b82f6;
}

input.invalid {
  border-color: #dc2626;
  background: #fef2f2;
}

.field-error {
  font-size: 0.78rem;
  color: #b91c1c;
  line-height: 1.3;
  min-height: 1.1em;
}

.calc-btn {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fff;
  background: #2563eb;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.calc-btn:hover {
  background: #1d4ed8;
}

.calc-btn:active {
  background: #1e40af;
}

.calc-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.conflict-free-btn {
  margin-top: 0.5rem;
  background: #7c3aed;
}

.conflict-free-btn:hover {
  background: #6d28d9;
}

.conflict-free-btn:active {
  background: #5b21b6;
}

.war-matrix-btn {
  margin-top: 0.5rem;
  background: #b45309;
}

.war-matrix-btn:hover {
  background: #92400e;
}

.war-matrix-btn:active {
  background: #78350f;
}

.war-matrix-intro {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.war-matrix-wrap {
  margin-top: 0.25rem;
}

.war-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.war-matrix th,
.war-matrix td {
  padding: 0.45rem 0.55rem;
  border: 1px solid #e2e8f0;
  text-align: center;
}

.war-matrix th {
  font-weight: 600;
  color: #334155;
  background: #f8fafc;
  vertical-align: middle;
}

.war-matrix-row-head,
.war-matrix-col-head {
  text-align: center;
}

.war-matrix-axis {
  display: inline-block;
}

.war-matrix-axis-col {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  max-width: 5.5rem;
}

.war-matrix-axis-row {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.war-matrix-code {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.war-matrix-char {
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.2;
  color: #64748b;
  max-width: 5.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.play-select-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.play-select-block > span {
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
}

.play-select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font-size: 0.95rem;
  color: #1e293b;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
}

.play-select:focus {
  outline: 2px solid #f59e0b;
  outline-offset: 1px;
}

.war-matrix-corner {
  background: #fff;
  border-color: transparent;
}

.war-matrix-diag {
  color: #94a3b8;
  background: #f1f5f9;
}

.war-matrix-cell {
  font-weight: 600;
  cursor: help;
}

.war-matrix-cell:hover {
  background: #fffbeb;
}

.play-comments {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #e2e8f0;
}

.play-comments-heading {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: #92400e;
}

.play-comments-levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.65rem;
}

.play-comment-level {
  padding: 0.55rem 0.65rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
}

.play-comment-level-title {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
  font-weight: 700;
  color: #b45309;
  text-align: center;
}

.play-comment-level-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #475569;
}

.play-comment-level-item {
  padding: 0.35rem 0;
  border-top: 1px solid #fde68a;
}

.play-comment-level-item:first-child {
  border-top: none;
  padding-top: 0;
}

.play-comment-heroes {
  font-weight: 600;
  color: #1e293b;
}

.play-comment-sep {
  margin: 0 0.2rem;
  color: #94a3b8;
}

.play-comment-text {
  color: #475569;
}

.batch-intro {
  margin: 0 0 0.85rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #5b21b6;
  background: #f5f3ff;
  border-radius: 6px;
  border: 1px solid #ddd6fe;
}

.batch-codes-line {
  margin: -0.35rem 0 0.85rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1.45;
  color: #334155;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  word-break: break-word;
}

.toggle-quads-btn {
  display: block;
  width: 100%;
  margin-top: 0.65rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #0f766e;
  background: #ecfdf5;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  cursor: pointer;
}

.toggle-quads-btn:hover {
  background: #d1fae5;
}

.toggle-quads-btn:focus {
  outline: 2px solid #14b8a6;
  outline-offset: 2px;
}

.quads-panel.is-collapsed {
  display: none;
}

.quads-hint {
  margin: 0.65rem 0 0.5rem;
  font-size: 0.82rem;
  color: #555;
  line-height: 1.4;
}

#quads-selected-count {
  font-weight: 600;
  color: #0f766e;
}

.quads-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.25rem 0 0.5rem;
}

.quad-btn {
  min-width: 3.1rem;
  padding: 0.4rem 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
}

.quad-btn-has-hint {
  color: #0f766e;
  background: #ecfdf5;
  border-color: #14b8a6;
}

.quad-btn:hover {
  background: #e2e8f0;
}

.quad-btn-has-hint:hover {
  background: #ccfbf1;
}

.quad-btn.is-active {
  color: #fff;
  background: #0f766e;
  border-color: #0d9488;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

.quad-btn-has-hint.is-active {
  color: #fff;
  background: #0f766e;
  border-color: #0d9488;
}

.quad-btn:focus {
  outline: 2px solid #14b8a6;
  outline-offset: 1px;
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.b-rows {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.b-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.b-row-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.b-row-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
}

.b-row-input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid #c5ccd6;
  border-radius: 6px;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  text-align: center;
}

.b-row-input:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
  border-color: #3b82f6;
}

.b-row-actions {
  display: flex;
  gap: 0.35rem;
  padding-top: 1.65rem;
  flex-shrink: 0;
}

.b-row-actions:empty {
  display: none;
}

.row-btn {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid #c5ccd6;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
}

.row-btn:hover {
  background: #e2e8f0;
}

.row-btn-add {
  color: #2563eb;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.row-btn-remove {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.batch-results {
  margin-bottom: 1rem;
}

.batch-block {
  padding: 0.75rem 0;
  border-bottom: 1px solid #eef1f4;
}

.batch-block .details-btn {
  margin-top: 0.5rem;
  margin-bottom: 0.35rem;
}

.batch-details.is-collapsed {
  display: none;
}

.batch-details .table-wrap {
  margin-top: 0.25rem;
}

.batch-block:last-child {
  border-bottom: none;
}

.batch-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}

.batch-error {
  margin: 0;
  font-size: 0.88rem;
  color: #b91c1c;
}

.results-hint {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: #666;
}

.results-summary {
  margin-bottom: 0.75rem;
}

.summary-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #444;
}

.details-btn {
  display: block;
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  cursor: pointer;
}

.details-btn:hover {
  background: #dbeafe;
}

.details-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.results-details.is-collapsed {
  display: none;
}

.table-wrap {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.results-table th,
.results-table td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid #eef1f4;
  vertical-align: top;
}

.results-table th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #666;
  background: #f8f9fb;
}

.results-table tbody tr:hover {
  background: #fafbfc;
}

.results-table .finale-name {
  font-weight: 600;
  white-space: nowrap;
}

.results-table tfoot .totals td {
  font-weight: 600;
  border-top: 2px solid #dde2e8;
  border-bottom: none;
  background: #f8f9fb;
}

.totals-finale-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.totals-finale-list li {
  padding: 0.2rem 0;
}

@media (max-width: 420px) {
  .inputs.sides {
    grid-template-columns: 1fr;
  }
}
