:root {
  --color-background: #030712;
  --color-background-alt: #0b1223;
  --color-surface: rgba(15, 23, 42, 0.62);
  --color-surface-strong: #101c34;
  --color-border: rgba(148, 163, 184, 0.28);
  --color-border-strong: rgba(148, 163, 184, 0.45);
  --color-white: #f8fafc;
  --color-text: #e2e8f0;
  --color-muted: #94a3b8;
  --color-accent: #38bdf8;
  --color-accent-strong: #0ea5e9;
  --color-purple: #6366f1;
  --color-success: #34d399;
  --color-danger: #f97373;
  --color-warning: #facc15;
  --shadow-elevated: 0 24px 48px rgba(8, 15, 31, 0.55);
  --shadow-soft: 0 16px 32px rgba(8, 15, 31, 0.4);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

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

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: radial-gradient(circle at 0% 0%, rgba(14, 165, 233, 0.16) 0%, transparent 40%),
    radial-gradient(circle at 100% 0%, rgba(99, 102, 241, 0.18) 0%, transparent 40%),
    linear-gradient(180deg, #050b1a 0%, #020617 100%);
  color: var(--color-text);
  line-height: 1.55;
  overflow-x: hidden;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.page-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 0;
}

.app-shell {
  width: min(1200px, 100% - 3rem);
  margin: 0 auto;
}

@media (max-width: 640px) {
  .app-shell {
    width: calc(100% - 1.5rem);
  }
}

.app-header {
  position: relative;
  padding: 2.5rem 0 2.2rem;
  color: var(--color-white);
  overflow: hidden;
}

.app-header::before,
.app-header::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  filter: blur(90px);
  opacity: 0.4;
}

.app-header::before {
  width: 320px;
  height: 320px;
  right: -120px;
  top: -160px;
  background: rgba(56, 189, 248, 0.6);
}

.app-header::after {
  width: 260px;
  height: 260px;
  left: -120px;
  bottom: -160px;
  background: rgba(99, 102, 241, 0.55);
}

.header-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.header-text {
  max-width: clamp(320px, 45vw, 520px);
}

.eyebrow {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
  margin: 0 0 0.75rem;
}

.header-text h1 {
  margin: 0 0 0.8rem;
  font-size: clamp(2.1rem, 3vw + 1rem, 2.8rem);
  font-weight: 700;
  line-height: 1.1;
}

.header-text p {
  margin: 0;
  color: rgba(248, 250, 252, 0.7);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.app-main {
  flex: 1;
  padding: 1.5rem 0 4rem;
}

.main-shell {
  display: flex;
  flex-direction: column;
  gap: 2.75rem;
}

.control-stack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.6rem;
}

.control-section {
  margin: 0;
  padding: 0;
  border: 0;
}

.control-section > summary {
  display: none;
}

.control-section .panel {
  margin: 0;
}

@media (max-width: 960px) {
  .control-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .control-stack {
    gap: 1.1rem;
  }
  details.control-section {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
  details.control-section > summary {
    display: block;
    padding: 1.05rem 1.5rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    list-style: none;
    color: var(--color-white);
    position: relative;
  }
  details.control-section[open] > summary {
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  }
  details.control-section > summary::-webkit-details-marker {
    display: none;
  }
  details.control-section > summary::after {
    content: "▾";
    position: absolute;
    right: 1.25rem;
    top: 50%;
    line-height: 1;
    transform: translateY(-50%);
    transition: transform 0.2s ease;
  }
  details.control-section[open] > summary::after {
    transform: translateY(-50%) rotate(180deg);
  }
  details.control-section .panel {
    border: 0;
    border-radius: 0;
    padding: 1.35rem 1.5rem 1.6rem;
  }
  details.control-section .panel-title {
    display: none;
  }
}

.stage-panel {
  display: flex;
  width: 100%;
}

.panel {
  background: var(--color-surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  box-shadow: var(--shadow-soft);
}

.panel-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-white);
}

.panel-hint {
  margin: 1rem 0 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.form-block {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 1.1rem;
}

.field-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(226, 232, 240, 0.9);
}

.form-control,
.form-select,
textarea.form-control,
textarea {
  width: 100%;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  color: var(--color-white);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  min-height: 2.75rem;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25);
}

.form-control::placeholder,
textarea::placeholder {
  color: rgba(226, 232, 240, 0.45);
}

#name-list {
  min-height: 200px;
  resize: vertical;
}

.field-group .form-control,
.field-group .form-select {
  flex: 1 1 180px;
}

.panel-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.panel-quick-actions .btn {
  flex: 1 1 auto;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.button-grid.alt {
  margin-top: 0.75rem;
}

.stage-card {
  width: 100%;
  background: rgba(15, 23, 42, 0.68);
  border: 1px solid var(--color-border);
  border-radius: 26px;
  padding: 2.2rem;
  box-shadow: var(--shadow-elevated);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.stage-tools {
  display: flex;
  gap: 1.2rem;
  align-items: stretch;
  margin-top: 0.8rem;
}

.stage-tools-panel {
  flex: 1 1 auto;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem 1.6rem;
  box-shadow: var(--shadow-soft);
}

.stage-tools-panel .panel-title {
  display: block;
  margin-top: 0;
}

.stage-tools .btn-print {
  align-self: center;
  padding: 0.8rem 1.4rem;
  min-width: 160px;
}

.stage-footnote {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.stage-footnote p {
  margin: 0;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.scale-control {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}

#print-container {
  width: calc(100% + 2.5rem);
  margin: 0 -1.25rem;
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.4);
  padding: 1.25rem;
  overflow: auto;
  display: flex;
  justify-content: center;
}

#grid-stage {
  width: 1123px;
  height: 694px;
  margin: 0 auto;
  position: relative;
  background: #f8fafc;
  border-radius: 18px;
  transform-origin: center center;
  transition: transform 0.3s ease;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

#grid-stage.students-view {
  transform: rotate(180deg);
}

#grid-container {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
}

.stage-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--color-muted);
}

.stage-footnote p {
  margin: 0;
  font-size: 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-purple) 100%);
  color: #021424;
  border-color: transparent;
  box-shadow: 0 10px 20px rgba(14, 165, 233, 0.22);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 26px rgba(14, 165, 233, 0.28);
}

.btn-secondary {
  background: rgba(56, 189, 248, 0.12);
  color: var(--color-accent);
  border-color: rgba(56, 189, 248, 0.4);
}

.btn-secondary:hover {
  background: rgba(56, 189, 248, 0.18);
}

.btn-outline-primary {
  background: transparent;
  color: var(--color-accent);
  border-color: rgba(56, 189, 248, 0.45);
}

.btn-outline-primary:hover {
  background: rgba(56, 189, 248, 0.12);
}

.btn-outline-dark {
  background: transparent;
  color: rgba(226, 232, 240, 0.85);
  border-color: rgba(226, 232, 240, 0.35);
}

.btn-outline-dark:hover {
  border-color: rgba(226, 232, 240, 0.6);
  background: rgba(148, 163, 184, 0.08);
}

.btn-outline-light {
  background: transparent;
  color: rgba(248, 250, 252, 0.9);
  border-color: rgba(248, 250, 252, 0.45);
}

.btn-outline-light:hover {
  background: rgba(248, 250, 252, 0.12);
}

.btn-light {
  background: rgba(248, 250, 252, 0.9);
  color: #05192f;
  border-color: transparent;
}

.btn-light:hover {
  background: rgba(248, 250, 252, 1);
}

.btn-success {
  background: rgba(52, 211, 153, 0.16);
  color: var(--color-success);
  border-color: rgba(52, 211, 153, 0.42);
}

.btn-success:hover {
  background: rgba(52, 211, 153, 0.22);
}

.btn-danger {
  background: rgba(249, 115, 115, 0.14);
  color: var(--color-danger);
  border-color: rgba(249, 115, 115, 0.4);
}

.btn-danger:hover {
  background: rgba(249, 115, 115, 0.22);
}

.btn-soft {
  background: rgba(148, 163, 184, 0.14);
  color: var(--color-white);
  border-color: rgba(148, 163, 184, 0.2);
}

.btn-soft[aria-pressed="true"],
.btn-soft:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.45);
  color: var(--color-white);
}

.btn-ghost {
  background: transparent;
  color: var(--color-muted);
  border-color: rgba(148, 163, 184, 0.18);
}

.btn-ghost:hover {
  color: var(--color-white);
  border-color: rgba(148, 163, 184, 0.42);
}

.btn-print {
  min-width: 160px;
}

textarea {
  border-radius: var(--radius-md);
}

.range-styled {
  -webkit-appearance: none;
  width: 180px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.25);
  outline: none;
}

.range-styled::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-purple) 100%);
  border: 2px solid var(--color-background-alt);
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(14, 165, 233, 0.35);
}

.range-styled::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-purple) 100%);
  border: 2px solid var(--color-background-alt);
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(14, 165, 233, 0.35);
}

/* Grid og romelementer */
.grid-item {
  width: 80px;
  height: 80px;
  position: absolute;
  background: linear-gradient(145deg, rgba(226, 232, 240, 0.95), rgba(203, 213, 225, 0.95));
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-radius: 10px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 6px;
  text-align: center;
  line-height: 1.2;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.15);
}

.grid-item .student-name {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.25;
  white-space: nowrap;
  color: #0f172a;
}

.grid-item .student-gender {
  font-size: 11px;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 12px;
  background-color: rgba(148, 163, 184, 0.18);
  color: #1e293b;
  text-transform: uppercase;
}

.grid-item[data-gender="male"] .student-gender {
  background-color: rgba(96, 165, 250, 0.35);
  color: #0f172a;
}

.grid-item[data-gender="female"] .student-gender {
  background-color: rgba(248, 113, 166, 0.3);
  color: #831843;
}

.grid-item[data-pair-label]::after {
  content: attr(data-pair-label);
  position: absolute;
  top: 4px;
  left: 4px;
  background-color: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 12px;
  pointer-events: none;
}

.grid-item .pair-count-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  min-width: 24px;
  padding: 2px 8px;
  border-radius: 12px;
  background-color: var(--color-purple);
  color: #f8fafc;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  box-shadow: 0 8px 16px rgba(79, 70, 229, 0.35);
  text-align: center;
}

[data-rotate] {
  --base-rotation: 0deg;
  --orientation-offset: 0deg;
  transform-origin: center center;
  transform: rotate(calc(var(--base-rotation) + var(--orientation-offset)));
}

#grid-stage.students-view [data-rotate] {
  --orientation-offset: 180deg;
}

.pair-label-hidden::after {
  display: none !important;
}

.grid-item.locked {
  background: linear-gradient(145deg, rgba(209, 250, 229, 0.95), rgba(134, 239, 172, 0.95));
  border-color: rgba(34, 197, 94, 0.5);
  cursor: not-allowed;
}

.tavle-box {
  position: absolute;
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: #f8fafc;
  text-align: center;
  font-weight: 700;
  border-radius: 10px;
  user-select: none;
  cursor: grab;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.4);
}

.feature-item {
  position: absolute;
  cursor: grab;
  border: 2px solid rgba(15, 23, 42, 0.5);
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.08);
  color: #0f172a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px;
  min-width: 52px;
  box-shadow: 0 12px 20px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(4px);
}

.feature-door {
  width: 74px;
  height: 28px;
  background: linear-gradient(135deg, #7f5539 0%, #4a2f1b 100%);
  color: #f8fafc;
  border-color: rgba(76, 47, 27, 0.7);
}

.feature-window {
  width: 104px;
  height: 20px;
  background: linear-gradient(180deg, rgba(191, 219, 254, 0.95) 0%, rgba(96, 165, 250, 0.85) 100%);
  color: #0f172a;
  border-color: rgba(59, 130, 246, 0.55);
}

.feature-item.locked {
  cursor: not-allowed;
  opacity: 0.75;
}

.swap-mode {
  outline: 1px dashed var(--color-purple);
}

.selected {
  border: 2px solid var(--color-purple);
}

/* Toast */
#toast {
  position: fixed;
  right: 32px;
  bottom: 32px;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  padding: 0.85rem 1.4rem;
  border-radius: 14px;
  font-size: 0.95rem;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  box-shadow: var(--shadow-soft);
  pointer-events: none;
  z-index: 1050;
}

#toast.toast-showing {
  pointer-events: auto;
}

#toast.toast-showing.show {
  opacity: 1;
  transform: translateY(0);
}

.history-content {
  max-height: 60vh;
  overflow: auto;
}

.history-content table {
  width: 100%;
  border-collapse: collapse;
  color: var(--color-text);
}

.history-content th,
.history-content td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.history-content th {
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  color: rgba(248, 250, 252, 0.7);
  text-transform: uppercase;
}

.history-content td {
  font-size: 0.9rem;
}

.release-notes-list {
  margin-bottom: 1.2rem;
  padding-left: 1.35rem;
  display: grid;
  gap: 0.45rem;
}

.release-notes-list li {
  color: var(--color-muted);
}

.text-muted {
  color: rgba(148, 163, 184, 0.78) !important;
}

/* Modal */
#info-modal,
#how-to-modal {
  position: fixed;
  z-index: 1200;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(3, 7, 18, 0.72);
  display: none;
  backdrop-filter: blur(6px);
}

.modal-dialog {
  max-width: 720px;
  margin: 6% auto;
}

.modal-content {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--color-border);
  border-radius: 22px;
  color: var(--color-white);
  box-shadow: var(--shadow-elevated);
}

#release-notes-modal .modal-content {
  background: rgba(15, 23, 42, 0.94);
}

.modal-header,
.modal-footer {
  border-color: rgba(148, 163, 184, 0.2);
  padding: 1.1rem 1.5rem;
}

.modal-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
  color: var(--color-text);
}

.btn-close {
  filter: invert(1);
}

.help-list {
  margin: 0;
  padding-left: 1.4rem;
  display: grid;
  gap: 0.5rem;
}

.help-list li {
  color: var(--color-text);
  font-size: 0.95rem;
}

.help-list li::marker {
  color: var(--color-accent);
  font-weight: 600;
}

.app-footer {
  margin-top: auto;
  padding: 2.5rem 0 2rem;
  background: rgba(2, 6, 23, 0.85);
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.footer-shell {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  align-items: center;
  color: rgba(248, 250, 252, 0.82);
}

.footer-meta p {
  margin: 0.1rem 0;
}

.footer-links {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.footer-support {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}

.old-version-link {
  color: rgba(248, 250, 252, 0.7);
}

.donation-link {
  color: #fbbf24;
  font-weight: 600;
}

.donation-link:hover {
  color: #facc15;
}

.qr-code {
  width: 96px;
  height: 96px;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

@media (max-width: 960px) {
  .control-panel {
    max-width: 100%;
  }
  .stage-card {
    padding: 1.4rem;
  }
  #grid-stage {
    transform-origin: center center;
  }
}

@media (max-width: 720px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }
  .stage-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .stage-tools {
    flex-direction: column;
  }
  .stage-tools .btn-print {
    width: 100%;
  }
  .scale-control {
    width: 100%;
  }
  .range-styled {
    width: 100%;
  }
  #toast {
    right: 50%;
    transform: translate(50%, 16px);
  }
  #toast.toast-showing.show {
    transform: translate(50%, 0);
  }
}

/* Utskrift */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  body * {
    visibility: hidden;
  }
  #grid-container,
  #grid-container * {
    visibility: visible;
  }
  #grid-stage {
    transform: none !important;
    width: 100% !important;
    height: auto !important;
  }
  #grid-container {
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: #fff !important;
    page-break-inside: avoid;
  }
  .grid-item {
    width: 80px;
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: none;
  }
  .grid-item.locked {
    background-color: #c3e6cb;
  }
  .tavle-box {
    background-color: #000;
    color: #fff;
    border-radius: 4px;
    box-shadow: none;
  }
  .feature-item {
    box-shadow: none;
  }
}
