:root {
  --color-bg: #f7f5f0;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-muted: #4a4a4a;
  --color-accent: #1f5c3f;
  --color-accent-contrast: #ffffff;
  --color-border: #c9c2b4;
  --square-light: #eeeed2;
  --square-dark: #769656;
  --square-selected: #ffd966;
  --square-legal: #4a90d9;
  --square-capture: #ff9e80;
  --square-check: #ff5252;
  --focus-ring: #0b5fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14171a;
    --color-surface: #1f2327;
    --color-text: #f0f0f0;
    --color-muted: #c7c7c7;
    --color-accent: #57c785;
    --color-accent-contrast: #0b1210;
    --color-border: #3a3f44;
    --square-legal: #3f7fae;
    --square-capture: #b1502f;
    --square-check: #c62828;
    --focus-ring: #7fb2ff;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", Verdana, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

a {
  color: var(--color-accent);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  padding: 0.75rem 1rem;
  z-index: 100;
  border-radius: 0 0 0.5rem 0;
}

.skip-link:focus {
  left: 0;
}

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
}

.site-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 60rem;
  margin: 0 auto;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.8rem);
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--color-muted);
  font-size: 0.95rem;
}

.site-header nav ul {
  list-style: none;
  display: flex;
  gap: 1rem;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.site-header nav a {
  text-decoration: none;
  font-weight: 600;
}

.site-header nav a:hover,
.site-header nav a:focus {
  text-decoration: underline;
}

.lang-toggle {
  background: transparent;
  border: 2px solid var(--color-accent);
  color: var(--color-accent);
  border-radius: 0.4rem;
  padding: 0.4rem 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.controls-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-end;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group.buttons,
.control-group.checkboxes {
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.control-group label {
  font-weight: 600;
  font-size: 0.9rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  font-size: 0.95rem;
}

select,
button {
  font-size: 1rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 2.5rem;
}

button {
  cursor: pointer;
}

.primary-btn {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border-color: var(--color-accent);
  font-weight: 700;
}

button:hover {
  filter: brightness(1.05);
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.board-section {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.move-history-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  width: min(13rem, 90vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: min(90vw, 34rem);
}

.move-history-heading {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
}

.move-history {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.move-history-empty {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.move-row {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr;
  gap: 0.4rem;
  padding: 0.2rem 0.3rem;
  border-radius: 0.3rem;
}

.move-row:nth-child(odd) {
  background: var(--color-bg);
}

.move-number {
  color: var(--color-muted);
  font-weight: 600;
}

.move-row.current-move {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.chess-board {
  display: flex;
  flex-direction: column;
  position: relative;
  border: 3px solid var(--color-accent);
  border-radius: 0;
  overflow: hidden;
  width: min(90vw, 34rem);
  aspect-ratio: 1 / 1;
}

.board-row {
  display: flex;
  flex: 1;
}

.square {
  flex: 1;
  aspect-ratio: 1 / 1;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
}

.square.light {
  background: var(--square-light);
}

.square.dark {
  background: var(--square-dark);
}

.square.selected {
  background: var(--square-selected) !important;
}

.square.last-move {
  box-shadow: inset 0 0 0 999px rgba(255, 214, 102, 0.25);
}

.square.in-check {
  background: var(--square-check) !important;
}

.square.legal-target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--square-legal);
  opacity: 0.85;
}

.square.legal-target.capture-target::after {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  background: transparent;
  border: 0.35rem solid var(--square-capture);
}

.piece-glyph {
  position: relative;
  z-index: 1;
  width: 78%;
  height: 78%;
  padding: 2%;
  pointer-events: none;
  /* Et lite "fotskygge" under brikken gjør den lettere å skille fra bakgrunnen. */
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.piece-ghost {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 5;
  will-change: transform;
  transition: transform 0.22s ease-in-out;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.live-status {
  min-height: 1.5rem;
  text-align: center;
  font-weight: 600;
  max-width: 34rem;
}

#alert-live {
  color: var(--color-accent);
}

.about-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1.25rem 1.5rem;
}

dialog {
  border-radius: 0.75rem;
  border: 1px solid var(--color-border);
  padding: 1.5rem;
  background: var(--color-surface);
  color: var(--color-text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.promotion-options {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.promotion-choice {
  font-size: 1.1rem;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.promotion-icon {
  width: 2rem;
  height: 2rem;
}

.game-over-dialog {
  position: relative;
  overflow: hidden;
  text-align: center;
  max-width: 26rem;
}

.game-over-heading {
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  margin: 0.5rem 0;
  color: var(--color-accent);
}

.game-over-message {
  font-size: 1.1rem;
  margin: 0 0 1.25rem;
}

.game-over-btn {
  font-size: 1.1rem;
  padding: 0.75rem 1.5rem;
}

.confetti-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.game-over-heading,
.game-over-message,
.game-over-btn {
  position: relative;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -5%;
  width: 0.6rem;
  height: 1rem;
  opacity: 0.9;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.95;
  }
  100% {
    /* Dialogen er ikke veldig høy, så en fast pikselavstand faller fint
       gjennom hele den synlige dialogboksen uten å virke for rask/treg. */
    transform: translateY(420px) rotate(540deg);
    opacity: 0.4;
  }
}

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}

/* Kompakt visning når siden lastes i en iframe på en annen nettside (?embed=1). */
.embed-mode .skip-link,
.embed-mode .site-header,
.embed-mode .site-footer,
.embed-mode .about-section {
  display: none;
}

.embed-mode main {
  padding: 0.75rem;
  gap: 1rem;
}

.embed-mode .controls-panel {
  padding: 0.75rem 1rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
