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

body {
  background: #f0ede8;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
}

/* ── Top bar (counter + language selector) ── */
.ui {
  align-self: flex-end;
  position: fixed;
  top: 20px;
  right: 28px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #2a2a2a;
}

#lang-select {
  background: #e8e4de;
  border: 1.5px solid #c8c3bb;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 500;
  color: #2a2a2a;
  cursor: pointer;
  outline: none;
}

#lang-select:focus {
  border-color: #999;
}

/* ── Map grid ── */
/* 15 cols × 15 rows — col 14 holds the tiny kingdoms vertically */
#map {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 4px;
  width: min(85vw, 600px);
  aspect-ratio: 1 / 1;
  position: relative;
}

/* ── Sea labels ── */
.sea-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: italic;
  font-size: clamp(6px, 0.85vw, 10px);
  color: #b0b8c4;
  letter-spacing: 0.06em;
  pointer-events: none;
  user-select: none;
}

#atlantic-label {
  grid-row: 8 / 11;       /* rows 7–9, beside France */
  grid-column: 1 / 4;     /* cols 0–2, west of France */
  writing-mode: vertical-lr;
  transform: rotate(180deg);
}

#mediterranean-label {
  grid-row: 14 / 15;      /* row 13, south of Spain + Italy */
  grid-column: 3 / 10;    /* cols 2–8 */
}

#baltic-label {
  grid-row: 4 / 7;        /* rows 3–5, sea cells east of Sweden */
  grid-column: 9 / 10;    /* col 8, between Sweden and Baltic states */
  writing-mode: vertical-lr;
  transform: rotate(180deg);
}

/* ── Tile base ── */
.tile {
  border-radius: 4px;
  border: 1px solid #d8d4ce;
  background: #f0ede8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: background 0.25s, border-color 0.25s;
}

.tile-label {
  font-size: clamp(6px, 1vw, 11px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: transparent;
  user-select: none;
}

/* ── Outer-edge bold borders ── */
.tile.outer-top    { border-top-color:    #555; border-top-width:    2px; }
.tile.outer-bottom { border-bottom-color: #555; border-bottom-width: 2px; }
.tile.outer-left   { border-left-color:   #555; border-left-width:   2px; }
.tile.outer-right  { border-right-color:  #555; border-right-width:  2px; }

/* ── Active tile ── */
.tile.active {
  border-color: #4a9e8a;
  border-width: 2px;
  animation: pulse 1.4s ease-in-out infinite;
}

.tile.active .tile-label {
  color: #4a9e8a;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* ── Revealed tiles ── */
.tile.revealed .tile-label { color: #fff; }

.tile.revealed.result-g1 { background: #1d6b50; border-color: #155840; }
.tile.revealed.result-g2 { background: #3d9680; border-color: #2e7a65; }
.tile.revealed.result-g3 { background: #6ab89e; border-color: #4e9880; }

.tile.revealed.result-r1 { background: #c8885c; border-color: #a86840; }
.tile.revealed.result-r2 { background: #c05840; border-color: #a03828; }
.tile.revealed.result-r3 { background: #963020; border-color: #782010; }

/* ── Wrong-answer shake ── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.shake {
  animation: shake 0.35s ease-in-out;
}

/* ── Input area ── */
.input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

#answer {
  background: #e8e4de;
  border: 1.5px solid #c8c3bb;
  border-radius: 10px;
  outline: none;
  font-size: 1.1rem;
  font-family: inherit;
  font-weight: 500;
  color: #2a2a2a;
  text-align: center;
  width: 260px;
  padding: 8px 16px;
  letter-spacing: 0.02em;
  transition: border-color 0.2s, background 0.2s;
}

#answer:focus {
  border-color: #999;
  background: #e2ddd7;
}

#answer::placeholder {
  color: #bbb;
  font-weight: 400;
}

#completion {
  font-size: 1rem;
  color: #2a2a2a;
  letter-spacing: 0.05em;
}

/* ── Hint display ── */
#hint {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #888;
  min-height: 1.4em;
  text-align: center;
  white-space: pre;  /* preserves the double-space gap at word boundaries */
}

/* ── Practice list ── */
#practice-list {
  width: min(85vw, 620px);
  margin-top: 8px;
}

#practice-heading {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #aaa;
  margin-bottom: 8px;
}

#practice-list table {
  width: 100%;
  border-collapse: collapse;
}

#practice-list td {
  padding: 3px 12px 3px 0;
  font-size: 0.85rem;
  color: #555;
  border: none;
}

#practice-list td:nth-child(odd) {
  font-weight: 700;
  font-family: 'Courier New', Courier, monospace;
  color: #4a9e8a;
  width: 2.5rem;
}

#practice-list td:nth-child(3) {
  padding-left: 1.5rem;
}
