:root {
  --bg: #0f172a;
  --bg-panel: #111827;
  --bg-panel-alt: #020617;
  --border: #1f2937;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.75);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: radial-gradient(circle at top, #1f2937 0, var(--bg) 55%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 1.2rem 1.5rem 0.6rem;
  background: linear-gradient(to bottom, rgba(15, 23, 42, 0.9), transparent);
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
}

.app-header .subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.app-main {
  flex: 1;
  padding: 0.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.panel {
  background: radial-gradient(circle at top left, #111827, #020617 55%);
  border-radius: var(--radius);
  border: 1px solid rgba(15, 23, 42, 0.9);
  box-shadow: var(--shadow-sm);
  padding: 0.8rem 0.9rem;
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  font-weight: 600;
}

/* Erweiterungen */

.expansion-controls {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.expansion-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.expansion-toggle input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Tabellenansicht */

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at top left, #020617, #020617 40%);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 450px;
}

thead {
  background: rgba(15, 23, 42, 0.95);
}

th,
td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(31, 41, 55, 0.8);
  white-space: normal; /* darf wieder umbrechen */
}

/* Nummern- und Siegpunkte-Spalte trotzdem kompakt und einzeilig lassen */
td.number-cell,
td.score-cell {
  white-space: nowrap;
}

th {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
}

tbody tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.7);
}

tbody tr:hover {
  background: rgba(31, 41, 55, 0.7);
}

/* Nummernspalte */

td.number-cell {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.number-cell {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.number-cell span:last-child {
  margin-left: auto;
  text-align: right;
  min-width: 2ch;
}

/* Siegpunkte-Spalte */

td.score-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.score-cell span {
  display: inline-block;
  min-width: 2.2rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent);
  font-size: 0.8rem;
  text-align: right;
}

/* Eingabefelder */

select.rotation-select,
input.prop-input {
  width: 100%;
  font-size: 0.8rem;
  padding: 0.2rem 0.3rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #020617;
  color: var(--text);
}

select.rotation-select:focus,
input.prop-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

td.prop-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Gesamtscore */

.total-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-lg);
  background: radial-gradient(circle at 10% 0, #111827, #020617 60%);
}

.total-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.total-score {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Layout-Anpassungen für größere Screens */

@media (min-width: 900px) {
  .app-main {
    flex-direction: row;
    align-items: flex-start;
  }

  /* Linkes Panel (Erweiterungen) bewusst schmal halten */
  .panel:nth-child(1) {
    flex: 0 0 260px;
    max-width: 260px;
  }

  /* Karten-Panel bekommt den ganzen Rest */
  .panel:nth-child(2) {
    flex: 1 1 auto;
    min-width: 600px;
  }

  .total-panel {
    flex-basis: 100%;
    margin-top: 0.2rem;
  }
}

/* Footer */

.app-footer {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(15, 23, 42, 0.9);
  background: rgba(15, 23, 42, 0.8);
}

/* Reset-Button */

#reset-state-button.reset-button {
  margin-top: 0.5rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  background-color: #eee;
  border: 1px solid #ccc;
  border-radius: 3px;
  cursor: pointer;
}

#reset-state-button.reset-button:hover {
  background-color: #e0e0e0;
}

/* Permanent-Marker */

.permanent-marker {
  margin-left: 0.2rem;
  font-size: 0.7em;
  color: #b36;
}

/* Umschalter Tabelle / Kacheln */

.layout-toggle {
  margin: 0.4rem 0 0.5rem;
  display: inline-flex;
  gap: 0.3rem;
}

.layout-button {
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #020617;
  color: var(--text-muted);
  cursor: pointer;
}

.layout-button--active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

/* Kachelansicht */

.tile-wrapper {
  margin-top: 0.5rem;
}

/* Kachelgitter: dynamische Spalten nur nach Fensterbreite */

.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* Kachelbreite ist fix, hängt nicht vom Inhalt ab */
.card-tile {
  flex: 0 0 260px;
  max-width: 260px;
  box-sizing: border-box;

  background: radial-gradient(circle at top left, #111827, #020617 55%);
  border-radius: var(--radius);
  border: 1px solid rgba(15, 23, 42, 0.9);
  box-shadow: var(--shadow-sm);
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Optional: auf sehr schmalen Bildschirmen 1 Spalte */
@media (max-width: 600px) {
  .card-tile {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

.card-tile-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.3rem;
}

.card-tile-number {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-name {
  font-weight: 600;
  font-size: 0.85rem;
}

/* Permanent-Marker auch in Kachelansicht nutzen */

.card-name .permanent-marker {
  margin-left: 0.2rem;
  font-size: 0.7em;
  color: #b36;
}

.card-tile-controls {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-rotation {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.card-rotation-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-property {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.card-property label {
  min-width: 70px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-tile-footer {
  margin-top: 0.1rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.3rem;
}

.card-tile-score-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Punkte-Badge in der Kachel – optisch ähnlich wie in der Tabelle */

.card-tile-score {
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* Regelkarten optisch leicht absetzen */

.card-tile.rule-card-tile {
  opacity: 0.9;
}

.card-rule-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Erweiterungs-Icons in Tabelle + Kacheln */

.expansion-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 4px;
  object-fit: contain;
  margin-right: 0.2rem;
  cursor: default; /* normaler Pfeil, kein Fragezeichen */
  transition: transform 0.1s ease-out, filter 0.1s ease-out;
}

.expansion-icon:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 0 3px rgba(148, 163, 184, 0.6));
}

/* Go-to-Karte Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: #020617;
  border-radius: var(--radius);
  border: 1px solid rgba(51, 65, 85, 0.8);
  box-shadow: var(--shadow-sm);
  padding: 0.75rem 0.9rem;
  min-width: 260px;
  max-width: 320px;
}

.modal-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}

.modal-field span {
  color: var(--text-muted);
}

.modal-field input,
.modal-field select {
  font-size: 0.85rem;
  padding: 0.15rem 0.3rem;
  border-radius: 0.2rem;
  border: 1px solid rgba(30, 64, 175, 0.6);
  background: #020617;
  color: var(--text);
}

.modal-error {
  min-height: 1rem;
  font-size: 0.75rem;
  color: #f97373;
  margin-bottom: 0.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.modal-actions button {
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #020617;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-actions button[type="submit"] {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-actions button:hover {
  filter: brightness(1.1);
}

.modal-hint {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
}

/* Erweiterungs-Header in der Tabelle */

.expansion-header-row {
  background: radial-gradient(circle at left, #111827, #020617 60%);
  border-top: 1px solid rgba(148, 163, 184, 0.4);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.expansion-number-cell {
  font-weight: 600;
}

.expansion-header-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Erweiterungs-Header in der Kachelansicht */

.expansion-header-tile {
  border-style: dashed;
  border-color: rgba(148, 163, 184, 0.9);
  background: linear-gradient(
    90deg,
    rgba(15, 23, 42, 0.95),
    rgba(30, 64, 175, 0.25)
  );
}

.expansion-header-tile-header {
  align-items: center;
}

.expansion-header-title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}