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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── DESIGN TOKENS (light mode) ──────────────────────────────────────────── */
:root {
  --ink:            #14151f;
  --bg-page:        #eef0f6;
  --bg-card:        #ffffff;
  --bg-cell:        #ffffff;
  --bg-cell-hover:  #f4f5fa;
  --border-cell:    #c7cad6;
  --border-divider: #e2e4ed;
  --text-main:      #15161f;
  --text-sub:       #6b6e82;
  --text-label:     #383a4a;
  --bg-clear:       #e7e9f1;
  --bg-clear-hover: #dadce8;
  --shadow:         0 1px 2px rgba(20,21,36,0.06), 0 6px 20px rgba(20,21,36,0.08);

  --green:          #6aaa64;
  --green-dark:     #2d6e28;
  --yellow:         #c9b458;
  --yellow-dark:    #8a7300;
  --grey-wordle:    #707476;
  --on-badge-light: #14151f;
  --accent:         #2b3fc9;
  --accent-dark:    #1f2e96;

  --starter-bg:     #eef0fb;
  --starter-border: #c7cdf0;
  --starter-hover:  #e1e5fa;
  --starter-copied-bg: #e2f5e1;
  --starter-copied-border: #6aaa64;
  --result-chip-bg: #f5f6fa;
  --result-chip-border: #e0e2ea;
  --result-chip-hover:  #e8eaf6;
  --best-guess-bg:  #ffffff;

  --select-arrow:   url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23383a4a' opacity='.7'/%3E%3C/svg%3E");
  --accent-wordmark: #3346d6;
  --font-display:   'Space Grotesk', system-ui, sans-serif;
  --font-body:      'Inter', system-ui, sans-serif;
}

body.dark {
  --bg-page:        #11121c;
  --bg-card:        #1c1e2e;
  --bg-cell:        #242638;
  --bg-cell-hover:  #2c2f45;
  --border-cell:    #3c3f58;
  --border-divider: #2a2c40;
  --text-main:      #ecedf6;
  --text-sub:       #9396ac;
  --text-label:     #c2c4d6;
  --bg-clear:       #242638;
  --bg-clear-hover: #2e3149;
  --shadow:         0 1px 2px rgba(0,0,0,0.3), 0 10px 28px rgba(0,0,0,0.35);

  --starter-bg:     #1d1f33;
  --starter-border: #34375a;
  --starter-hover:  #262a47;
  --starter-copied-bg: #14271a;
  --starter-copied-border: #4a8a44;
  --result-chip-bg: #1d1f33;
  --result-chip-border: #34375a;
  --result-chip-hover:  #262a47;
  --best-guess-bg:  #1c1e2e;

  --accent:         #6c7dff;
  --accent-dark:    #8b99ff;

  --select-arrow:   url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23c2c4d6' opacity='.8'/%3E%3C/svg%3E");
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

.icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  vertical-align: -2px;
}

/* ── BANNER ───────────────────────────────────────────────────────────────── */
.banner {
  background: var(--ink);
  color: white;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid var(--accent);
}

.banner-inner {
  width: 100%;
  max-width: 680px;
  display: flex;
  justify-content: center;
}

/* Wordmark: brand name rendered as letter tiles, like the solver's own grid.
   Tiles flex-grow to fill the same width as the main container below. */
.wordmark {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}
.wordmark-tile {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  aspect-ratio: 0.8;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  -webkit-text-stroke: 0.6px currentColor;
  color: white;
  text-transform: uppercase;
}
.wm-green   { background: var(--green); }
.wm-yellow  { background: var(--yellow); }
.wm-accent  { background: var(--accent-wordmark); }
.wordmark-suffix {
  flex-shrink: 0;
  margin-left: 6px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  -webkit-text-stroke: 0.5px currentColor;
  letter-spacing: 0.04em;
  color: rgba(255,255,255,0.6);
}

/* Theme toggle */
.theme-toggle {
  background: var(--bg-cell);
  border: 1.5px solid var(--border-cell);
  border-radius: 0;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.theme-toggle .icon { width: 16px; height: 16px; vertical-align: 0; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
body.dark .theme-toggle .icon-sun { display: block; }
body.dark .theme-toggle .icon-moon { display: none; }

/* ── TOOLBAR (inside main container) ─────────────────────────────────────── */
.toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}
.word-length-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.word-length-wrap label {
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  white-space: nowrap;
}
#wordLength {
  font-family: var(--font-body);
  background: var(--bg-cell);
  border: 1.5px solid var(--border-cell);
  color: var(--text-main);
  border-radius: 0;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 28px;
  transition: border-color 0.15s;
}
#wordLength:hover { border-color: var(--accent); }
#wordLength:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
#wordLength option { background: var(--bg-cell); color: var(--text-main); }

/* ── CONTAINER ────────────────────────────────────────────────────────────── */
.layout {
  max-width: 680px;
  margin: 32px auto;
}

.container,
.sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-divider);
  border-radius: 0;
  padding: 32px 36px;
  box-shadow: var(--shadow);
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.container {
  margin-bottom: 24px;
}

/* På tillräckligt breda fönster får "Unika ord" och "Möjliga ord" en egen
   container till höger om huvudcontainern istället för att staplas under. */
@media (min-width: 1240px) {
  .layout {
    max-width: 1140px;
    display: flex;
    align-items: flex-start;
    gap: 24px;
  }
  .container {
    width: 680px;
    flex-shrink: 0;
    margin-bottom: 0;
  }
  .sidebar {
    flex: 1;
    min-width: 0;
  }
}

/* ── SECTIONS ─────────────────────────────────────────────────────────────── */
.section { margin-bottom: 4px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── BADGES ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 0;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-green   { background: var(--green);       color: var(--on-badge-light); }
.badge-yellow  { background: var(--yellow);      color: var(--on-badge-light); }
.badge-grey    { background: var(--grey-wordle); color: white; }
.badge-starter { background: var(--accent);      color: white; }

/* ── WORDLE GRID ──────────────────────────────────────────────────────────── */
.wordle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.wordle-cell {
  width: 54px;
  height: 54px;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  background: var(--bg-cell);
  color: var(--text-main);
  border: 2px solid var(--border-cell);
  border-radius: 0;
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s, background 0.2s, color 0.2s;
  caret-color: transparent;
}
.wordle-cell:hover { background: var(--bg-cell-hover); }
.wordle-cell:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 63, 201, 0.25);
}
.wordle-cell.green  { background: var(--green);       color: white; border-color: var(--green-dark); }
.wordle-cell.yellow { background: var(--yellow);      color: white; border-color: var(--yellow-dark); }
.wordle-cell.grey   { background: var(--grey-wordle); color: white; border-color: var(--grey-wordle); }

.wordle-cell.green:focus  {
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.8), 0 0 0 5px var(--green-dark);
}
.wordle-cell.yellow:focus {
  border-color: var(--yellow-dark);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.8), 0 0 0 5px var(--yellow-dark);
}

.wordle-cell::selection,
.absent-cell::selection { background: transparent; }
.wordle-cell::-moz-selection,
.absent-cell::-moz-selection { background: transparent; }

/* ── ROW WRAPS ────────────────────────────────────────────────────────────── */
.yellow-row-wrap,
.absent-row-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.remove-row-btn {
  width: 28px;
  height: 28px;
  border-radius: 0;
  border: 1.5px solid transparent;
  background: var(--bg-clear);
  color: var(--text-label);
  font-family: var(--font-display);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.remove-row-btn:hover { background: #d8434a; color: white; }
.remove-row-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.remove-row-btn.hidden { visibility: hidden; }

/* ── ABSENT CELL ──────────────────────────────────────────────────────────── */
.absent-cell {
  width: 44px;
  height: 44px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  background: var(--bg-cell);
  color: var(--text-main);
  border: 2px solid var(--border-cell);
  border-radius: 0;
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s, background 0.2s;
  caret-color: transparent;
}
.absent-cell:hover { background: var(--bg-cell-hover); }
.absent-cell:focus {
  border-color: var(--grey-wordle);
  box-shadow: 0 0 0 3px rgba(120, 124, 126, 0.3);
}

/* Drag-och-släpp mellan bokstavsrutor */
.wordle-cell[draggable="true"]:hover,
.absent-cell[draggable="true"]:hover {
  cursor: grab;
}
.wordle-cell.dragging,
.absent-cell.dragging {
  opacity: 0.35;
}
.wordle-cell.drag-over,
.absent-cell.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}
.clear-btn:hover { background: var(--bg-clear); color: var(--text-main); }
.clear-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.add-row-btn {
  background: none;
  border: 1.5px dashed var(--border-cell);
  color: var(--text-sub);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 0;
  cursor: pointer;
  margin-top: 2px;
  transition: border-color 0.15s, color 0.15s;
}
.add-row-btn:hover { border-color: var(--accent); color: var(--accent); }
.add-row-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.divider {
  border: none;
  border-top: 1px solid var(--border-divider);
  margin: 22px 0;
}

/* ── ACTIONS ──────────────────────────────────────────────────────────────── */
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.btn-clear-all {
  background: var(--bg-clear);
  color: var(--text-label);
  border: 1.5px solid transparent;
  padding: 11px 20px;
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-clear-all:hover { background: var(--bg-clear-hover); }
.btn-clear-all:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── RESULTS ──────────────────────────────────────────────────────────────── */
.best-guess-box {
  position: relative;
  background: var(--best-guess-bg);
  border: 1.5px solid var(--border-divider);
  border-radius: 0;
  padding: 16px 22px;
  margin: 4px 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.best-guess-box.copied { background: var(--starter-copied-bg); border-color: var(--starter-copied-border); }
/* Signature corner-bracket marks, like an instrument readout */
.best-guess-box::before,
.best-guess-box::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.best-guess-box::before {
  top: -2px;
  left: -2px;
  border-top: 2px solid var(--accent);
  border-left: 2px solid var(--accent);
}
.best-guess-box::after {
  bottom: -2px;
  right: -2px;
  border-bottom: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
}
.best-guess-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.best-guess-word {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-main);
  text-transform: uppercase;
}

.results-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.result-chip {
  background: var(--result-chip-bg);
  border: 1.5px solid var(--result-chip-border);
  border-radius: 0;
  padding: 6px 12px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-main);
  transition: background 0.12s, border-color 0.12s;
  cursor: pointer;
}
.result-chip:hover { background: var(--result-chip-hover); border-color: var(--accent); }
.result-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.result-chip.copied { background: var(--starter-copied-bg); border-color: var(--starter-copied-border); }

/* ── STARTER WORDS ────────────────────────────────────────────────────────── */
.starter-sub {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-sub);
}
.starter-words-loading {
  font-family: var(--font-body);
  color: var(--text-sub);
  font-size: 0.85rem;
  padding: 6px 0;
}
.starter-words {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 0 2px;
  transition: opacity 0.2s;
}
.starter-words.fading-out {
  opacity: 0;
}
.starter-card {
  font-family: var(--font-body);
  text-align: center;
  background: var(--starter-bg);
  border: 1.5px solid var(--starter-border);
  border-radius: 0;
  padding: 11px 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.starter-card:hover {
  background: var(--starter-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.starter-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.starter-card.copied { background: var(--starter-copied-bg); border-color: var(--starter-copied-border); }

.starter-word {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--accent);
  text-transform: uppercase;
}
.starter-letters { display: flex; gap: 3px; }
.starter-letter-chip {
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 0;
  background: var(--accent);
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.starter-score {
  font-family: var(--font-body);
  font-size: 0.7rem;
  color: var(--text-sub);
}

@media (max-width: 520px) {
  .banner { padding: 12px 16px; }
  .layout { margin: 16px; }
  .container, .sidebar { padding: 22px 18px; }
  .container { margin-bottom: 16px; }
  .wordle-cell { width: 40px; height: 40px; font-size: 1.2rem; }
  .absent-cell { width: 34px; height: 34px; font-size: 1rem; }
  .wordmark-tile { font-size: 0.8rem; }
  .wordmark-suffix { font-size: 0.78rem; }
}

/* ── FOOTER ───────────────────────────────────────────────────────────────── */
footer {
  max-width: 680px;
  margin: 0 auto 40px;
  padding: 0 36px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-sub);
  text-align: center;
  line-height: 1.5;
}

@media (min-width: 1240px) {
  footer { max-width: 1140px; }
}

@media (max-width: 520px) {
  footer { margin: 0 16px 24px; padding: 0 18px; }
}
