:root {
  color-scheme: dark light;
  font-family: system-ui, sans-serif;
  --bg: #0f1014;
  --panel: #1b1d24;
  --border: #3c3f4a;
  --text: #f7f1e3;
  --text-muted: #c7c1b6;
  --primary: #d87b32;
  --primary-hover: #f09342;
  --primary-border: #a86227;
  --accent: #d9b66d;
  --info: #6fa3c8;
  --error: #d9544f;
  --success: #7adf9c;
  --input-bg: #13151d;
  --muted-bg: rgba(59, 130, 246, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #e8761f;
    --primary-hover: #ff912f;
    --primary-border: #b35815;
  }

  button {
    color: #fff;
  }

  button:hover:not(:disabled) {
    background: var(--primary-hover);
  }

  .remove-btn:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.35);
    border-color: rgba(59, 130, 246, 0.65);
    color: #f0f5ff;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f1e5;
    --panel: #fffaf1;
    --border: #d6c8b6;
    --text: #2a2620;
    --text-muted: #615649;
    --primary: #e58b3e;
    --primary-hover: #f39b4c;
    --primary-border: #c46f2a;
    --accent: #c28d3d;
    --info: #3f7bab;
    --error: #c74a45;
    --success: #6fbf7a;
    --input-bg: #fffdf8;
    --muted-bg: rgba(189, 150, 104, 0.12);
  }

  button:hover:not(:disabled) {
    background: var(--primary-hover);
  }
}

body {
  margin: 0;
  padding: 1.5rem;
  background: var(--bg);
  color: var(--text);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  background: var(--primary);
  color: #0f1014;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  z-index: 1000;
}

.skip-link:focus {
  left: 0.5rem;
}

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

.header-title {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.header-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0.35rem;
}

.icon-btn img {
  width: 1.5rem;
  height: 1.5rem;
}

.info-guide-btn {
  border-radius: 999px;
  background: var(--muted-bg);
  border-color: var(--border);
}

.info-guide-btn:hover:not(:disabled) {
  border-color: var(--primary-border);
}

.info-guide-btn:focus-visible,
.modal-close-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.session-code {
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--muted-bg);
  font-size: 0.95rem;
}

h1,
h2 {
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

button,
input,
select,
textarea {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
}

textarea {
  min-height: 3rem;
  resize: vertical;
}

button {
  cursor: pointer;
  border-color: var(--primary-border);
  background: var(--primary);
}

.hidden {
  display: none !important;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

main {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

.card-row {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(0, 2.2fr) minmax(240px, 1fr);
}

.card-row.single-column {
  grid-template-columns: 1fr;
}

@media (max-width: 900px) {
  .card-row {
    grid-template-columns: 1fr;
  }
}

.card-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.stack {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.stack > * {
  flex: 1 1 260px;
  min-width: 240px;
}

.status {
  font-size: 0.95rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.status-online {
  background: rgba(102, 184, 131, 0.16);
  border: 1px solid rgba(102, 184, 131, 0.4);
}

.status-offline {
  background: rgba(217, 84, 79, 0.14);
  border: 1px solid rgba(217, 84, 79, 0.4);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.65rem;
}

li {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--muted-bg);
}

.highlight {
  border-color: var(--accent);
  background: rgba(217, 182, 109, 0.15);
}

.current-turn {
  border-color: var(--success);
  background: rgba(122, 223, 156, 0.28);
  position: relative;
}

.past-turn {
  opacity: 0.6;
}

.past-badge {
  background: rgba(229, 139, 62, 0.22);
  color: var(--text);
}

.current-turn::before {
  content: '▶';
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--success);
  font-size: 0.8rem;
}

form {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

label {
  display: grid;
  gap: 0.2rem;
  font-size: 0.9rem;
}

.field-error {
  font-size: 0.8rem;
  color: var(--error);
}

.message {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--muted-bg);
  border: 1px solid rgba(63, 133, 246, 0.25);
  display: none;
}

.message.visible {
  display: block;
}

.badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--primary-border);
  background: rgba(216, 123, 50, 0.18);
  color: var(--text);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.type-badge {
  margin-left: 0;
  margin-top: 0.35rem;
  display: inline-block;
  width: fit-content;
}

@media (prefers-color-scheme: light) {
  .badge {
    background: rgba(229, 139, 62, 0.15);
    border-color: rgba(196, 111, 42, 0.6);
    color: #3a2d21;
  }

  .current-turn {
    background: rgba(111, 191, 122, 0.24);
  }
}

.effects {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.sorted-highlight {
  outline: 2px dashed rgba(229, 139, 62, 0.6);
  outline-offset: 4px;
}

.effect-chip {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  background: rgba(216, 123, 50, 0.16);
  border-radius: 12px;
  padding: 0.2rem 0.5rem;
}

.effect-chip button {
  margin-left: auto;
  flex-shrink: 0;
}

@media (prefers-color-scheme: light) {
  .effect-chip {
    background: rgba(216, 123, 50, 0.14);
  }
}

.remove-btn {
  padding: 0.15rem 0.4rem;
  font-size: 0.8rem;
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.4);
  color: #dce7ff;
  margin-left: auto;
  flex-shrink: 0;
}

@media (prefers-color-scheme: light) {
  .remove-btn {
    background: rgba(229, 139, 62, 0.16);
    border-color: rgba(229, 139, 62, 0.5);
    color: #7a3e0f;
  }

  .remove-btn:hover:not(:disabled) {
    background: rgba(229, 139, 62, 0.28);
    border-color: rgba(196, 111, 42, 0.75);
    color: #5a2c08;
  }
}

.remove-btn[data-role="gm-only"] {
  opacity: 0.85;
}

.label {
  font-size: 0.85rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.section-header {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.initiative-nav {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.initiative-nav button {
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
}

.initiative-list-wrap {
  margin-top: 0.45rem;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 0.2rem;
  scroll-behavior: smooth;
}

.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.button-row > * {
  flex: 1 1 180px;
}

.button-row button {
  width: 100%;
}

.button-row--wrap {
  flex-wrap: wrap;
}

.button-column {
  display: grid;
  gap: 0.5rem;
}

.last-action-text {
  min-height: 1.2rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.radio-keyboard-hint {
  margin: 0.35rem 0 0.6rem;
  font-size: 0.82rem;
  color: #4b5563;
}

.session-info {
  margin-top: 0.6rem;
}

.current-player-box {
  padding: 0.75rem 0.9rem;
  border: 1px dashed #374151;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.12);
  margin-bottom: 0.75rem;
}

.order-list li {
  border-color: #6b7280;
  background: rgba(59, 130, 246, 0.08);
}

/* Tie-Break Buckets in Session Übersicht */
.bucket-wrapper {
  border: 1px dashed #4b5563;
  border-radius: 6px;
  padding: 0.5rem;
  background: rgba(55, 65, 81, 0.35);
  margin-bottom: 0.5rem;
}

@media (prefers-color-scheme: light) {
  .bucket-wrapper {
    border-color: #d6c8b6;
    background: rgba(189, 150, 104, 0.12);
  }
}

.bucket-header {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 0.4rem;
}

.bucket-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.bucket-list .player-item {
  cursor: move;
}

.bucket-list .player-item.dragging {
  opacity: 0.6;
}

.player-label {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.player-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  flex-direction: column;
}

.player-header {
  width: 100%;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.player-header button {
  margin-left: auto;
  flex-shrink: 0;
}

.upload-btn {
  font-size: 1rem;
}

.gamestate-actions {
  margin-top: 0.75rem;
}

.gamestate-title {
  margin-bottom: 0.25rem;
}

.gamestate-subsection-title {
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}

.gamestate-primary-form {
  margin-top: 0;
}

.btn-primary-emphasis,
.btn-secondary-muted {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.btn-primary-emphasis img,
.btn-secondary-muted img {
  width: 1rem;
  height: 1rem;
}

.gamestate-primary-form .btn-primary-emphasis {
  grid-column: 1 / -1;
  width: 100%;
}

.gamestate-secondary-row {
  align-items: stretch;
}

.upload-trigger-wrap {
  display: block;
}

.upload-trigger-wrap button {
  width: 100%;
}

.btn-secondary-muted {
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.btn-secondary-muted:hover:not(:disabled) {
  border-color: var(--primary-border);
  background: var(--muted-bg);
  color: var(--text);
}

.event-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.event-item button {
  margin-left: auto;
  flex-shrink: 0;
}

.effect-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.effect-item button {
  margin-left: auto;
  flex-shrink: 0;
}

.wide-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 0.8rem;
  margin-top: 0.75rem;
}

.wide-form select,
.wide-form input {
  width: 100%;
  min-width: 0; /* verhindert Überlappen bei langen Placeholdern/Optionen */
}

#initiativeForm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
}

#initiativeForm select,
#initiativeForm input[type="number"],
#initiativeForm input[type="text"] {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#initiativeForm button {
  width: 100%;
  align-self: stretch;
}

.wide-form button {
  grid-column: 1 / -1;
  width: 100%;
}

#createNpcFields button,
#createEventFields button {
  margin-top: 0.35rem;
}

.form-divider {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted-text);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.turns-section {
  display: grid;
  gap: 0.5rem;
}

.turn-list {
  display: grid;
  gap: 0.5rem;
}

.turn-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.35rem;
}

/* Tie-Break Drag & Drop Styles entfernt */

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem 0.75rem;
  align-items: end;
  margin-top: 0.75rem;
}

.inline-form button {
  grid-column: 1 / -1;
  width: fit-content;
}

.inline-form .field-error {
  grid-column: 1 / -1;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  align-items: start;
}

.log-list li {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.45);
  font-size: 0.9rem;
}

.log-time {
  font-size: 0.75rem;
  opacity: 0.7;
}

.checkbox-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  font-size: 0.9rem;
}

.inline-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.inline-row .grow {
  width: 100%;
}

#effectForm .inline-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

@media (max-width: 720px) {
  body {
    padding: 1rem;
  }

  .card {
    padding: 0.9rem 1rem;
  }

  .wide-form {
    grid-template-columns: 1fr;
  }

  #effectForm .inline-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .inline-checkbox {
    justify-content: flex-start;
  }
}

.inline-checkbox {
  justify-content: flex-start;
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.radio-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem 0.5rem;
  display: grid;
  gap: 0.35rem;
  background: var(--muted-bg);
}

.radio-group.compact {
  padding: 0.4rem 0.6rem 0.35rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.radio-group legend {
  font-size: 0.85rem;
  color: var(--muted-text);
  padding: 0 0.4rem;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

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

.hint-overlay {
  display: none;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(248, 180, 0, 0.5);
  background: rgba(248, 180, 0, 0.12);
  color: #fbbf24;
  font-size: 0.9rem;
}

.hint-overlay.visible {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 12, 16, 0.72);
}

.modal-dialog {
  width: min(760px, 100%);
  max-height: min(85vh, 820px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
  padding: 1rem 1.1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.modal-close-btn {
  white-space: nowrap;
}

.modal-intro {
  margin-top: 0;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.shortguide-section {
  margin-top: 0.8rem;
}

.shortguide-section h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.shortguide-section p {
  margin: 0;
}

.shortguide-section ul {
  display: grid;
  gap: 0.45rem;
  margin: 0;
}

body.modal-open {
  overflow: hidden;
}

.toast-region {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1300;
  width: min(420px, calc(100vw - 2rem));
  display: grid;
  gap: 0.5rem;
  pointer-events: none;
}

.toast-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
  padding: 0.85rem 0.95rem;
  font-size: 1rem;
  line-height: 1.45;
  min-height: 3.2rem;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 0.7rem;
  pointer-events: auto;
  animation: toast-in 180ms ease-out;
  --toast-accent: var(--info);
}

.toast-body {
  display: block;
}

.toast-icon {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.08rem;
  flex-shrink: 0;
  background-color: var(--toast-accent);
  -webkit-mask: url('/assets/icons/attention-icon.svg') no-repeat center / contain;
  mask: url('/assets/icons/attention-icon.svg') no-repeat center / contain;
}

.toast-item.toast-info {
  border-left-color: var(--info);
  --toast-accent: var(--info);
}

.toast-item.toast-success {
  border-left-color: var(--success);
  --toast-accent: var(--success);
}

.toast-item.toast-warning {
  border-left-color: var(--accent);
  --toast-accent: var(--accent);
}

.toast-item.toast-error {
  border-left-color: var(--error);
  --toast-accent: var(--error);
}

.toast-item.toast-event {
  border-left-color: var(--success);
  --toast-accent: var(--success);
}

.site-footer {
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  font-size: 0.95rem;
}

.site-footer a {
  color: var(--accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Die NPC Badge */
.npc-badge {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}

@media (prefers-color-scheme: light) {
  .npc-badge {
    background: rgba(210, 99, 99, 0.18);
    border-color: rgba(210, 99, 99, 0.5);
    color: #a12e2e;
  }
}

@media (max-width: 720px) {
  .header-meta {
    gap: 0.45rem;
  }

  .session-code,
  .status {
    font-size: 0.85rem;
    padding: 0.4rem 0.55rem;
  }

  .modal-backdrop {
    padding: 0.55rem;
  }

  .modal-dialog {
    width: 100%;
    max-height: 90vh;
    padding: 0.85rem 0.85rem 1rem;
  }

  .toast-region {
    right: 0.6rem;
    left: 0.6rem;
    top: 0.7rem;
    width: auto;
  }
}
