/*
 * Everything laid out takes its colours from here; everything drawn takes them
 * from src/ui/colors.ts, because Canvas 2D cannot read custom properties. The
 * two overlap only in --surface and --accent, which must be kept in step by hand.
 */

:root {
  color-scheme: light dark;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --surface: #ffffff;
  --raised: #f4f4f4;
  --edge: #d4d4d4;
  --accent: #009900;
  --danger: #cc0000;
  --radius: 10px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e6e6;
    --muted: #9a9a9a;
    --surface: #121212;
    --raised: #1e1e1e;
    --edge: #333333;
    --accent: #7ccf7c;
    --danger: #ff5c5c;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 100dvh;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  color: var(--ink);
  background: var(--surface);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- chrome ------------------------------------------------------------- */

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  max-width: 640px;
}

h1 {
  margin: 0;
  flex: 1 1 auto;
  font-size: 1.35rem;
  font-weight: 600;
}

header nav {
  font-size: 0.9rem;
}

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

.back {
  min-height: auto;
  padding: 4px 10px;
  font-size: 0.9rem;
}

main {
  width: 100%;
  max-width: 640px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
}

.banner {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--raised);
  font-size: 0.9rem;
}

/* --- screens ------------------------------------------------------------ */

.screen {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
}

.board-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.side {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

canvas {
  display: block;
  max-width: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

#size-board {
  pointer-events: none;
  cursor: default;
}

canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

p[role='status'] {
  margin: 0;
  min-height: 1.5em;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.alert {
  margin: 0;
  color: var(--danger);
  font-size: 0.95rem;
}

/* --- controls ----------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

button,
.button,
select,
input[type='text'] {
  min-height: var(--tap);
  padding: 8px 16px;
  font: inherit;
  color: var(--ink);
  background: var(--raised);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

button.primary,
.button.primary {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

button:disabled,
.button[aria-disabled='true'] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

button:focus-visible,
.button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.rows {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 6px 0;
  border-bottom: 1px solid var(--edge);
}

.stepper {
  display: inline-flex;
  gap: 6px;
}

.stepper button {
  min-width: var(--tap);
  padding: 8px;
}

.field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field input {
  width: 100%;
}

progress {
  width: 100%;
  height: 10px;
}

.explain {
  width: 100%;
  font-size: 0.9rem;
  color: var(--muted);
}

.explain summary {
  cursor: pointer;
  padding: 6px 0;
}

/* --- the boards list ---------------------------------------------------- */

.board-list {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.board-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--raised);
}

.row-open {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 0;
  padding: 4px;
  border: none;
  background: none;
  text-align: left;
}

.row-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  cursor: inherit;
}

.row-name {
  flex: 1 1 auto;
  font-weight: 500;
}

.row-size {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.row-actions,
.row-confirm {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions button,
.row-confirm button {
  min-height: 36px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.row-up,
.row-down {
  min-width: 36px;
  padding: 4px 8px;
}

.row-delete,
.row-confirm-yes {
  color: var(--danger);
  border-color: var(--danger);
}

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

/* --- landscape ---------------------------------------------------------- */

@media (orientation: landscape) and (min-width: 700px) {
  main {
    max-width: 900px;
  }

  #screen-play,
  #screen-visualize,
  #screen-holes,
  #screen-vacancy,
  #screen-size {
    /* Board left, its controls in a rail on the right. The rail is one element
       so the board keeps the whole of the first column and the full row height —
       otherwise the slot takes its height from the canvas inside it, and sizing
       the canvas from the slot would have nothing to measure. */
    flex-direction: row;
    align-items: stretch;
    gap: 20px;
  }

  .side {
    flex: 0 0 240px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    min-height: 0;
  }

  .side .controls {
    flex-direction: column;
    align-items: stretch;
  }

  #screen-play > .controls,
  #screen-visualize > .controls,
  #screen-holes > .controls,
  #screen-vacancy > .controls,
  #screen-size > .controls {
    flex-direction: column;
    align-items: stretch;
  }
}
