:root {
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-dark: #1a1a1a;
  --color-text: var(--color-dark);
  --color-text-on-accent: #ffffff;
  --color-text-muted: #6b7280;
  --color-text-subtle: #374151;
  --color-letter-value: #4b5563;
  --color-accent: #2051be;
  --color-success: #0e9a41;
  --color-danger: #fecaca;
  --color-disabled: #9ca3af;
  --color-button-bg: #e5e7eb;
  --color-backdrop: rgb(0 0 0 / 50%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 2rem;
  gap: 1rem;
  font-family: system-ui, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
}

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.status-display {
  display: flex;
  gap: 1rem;
}

/* `display: flex` above always wins over the browser's built-in
   `[hidden] { display: none }` rule (author styles beat UA styles
   regardless of specificity) - without this, setting .hidden in JS has no
   visible effect and both the status line and the violation message show
   at once. */
.status-display[hidden] {
  display: none;
}

#word-count-display,
#score-display,
#timer-display {
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

#violation-display {
  font-size: 1.1rem;
  font-weight: bold;
}

footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

#copyright {
  font-size: 0.75rem;
}

/* #help-info's own display/gap replicates the 1rem spacing body's flex
   layout gives its direct children - wrapping the three sections in one
   toggleable container took them out of that direct-child gap. */
#help-info {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* `display: flex` above always wins over the browser's built-in
   `[hidden] { display: none }` rule (author styles beat UA styles
   regardless of specificity) - see the identical .status-display[hidden]
   fix above. Without this, toggling the `hidden` attribute in main.js
   would have no visible effect. */
#help-info[hidden] {
  display: none;
}

#how-to-play,
#rule-violations,
#useful-info {
  max-width: 20rem;
  font-size: 0.875rem;
  color: var(--color-text-subtle);
}

#how-to-play h2,
#rule-violations h2,
#useful-info h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

#how-to-play ul,
#rule-violations ul,
#useful-info ul {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

button {
  font-size: 1rem;
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.mode-buttons {
  display: flex;
  gap: 0.5rem;
}

.mode-buttons button {
  background-color: var(--color-button-bg);
  color: var(--color-text);
}

.mode-buttons button.active {
  background-color: var(--color-dark);
  color: var(--color-text-on-accent);
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--size), 3rem);
  grid-template-rows: repeat(var(--size), 3rem);
  gap: 2px;
  background-color: var(--color-dark);
  padding: 2px;
}

.cell-wrapper {
  position: relative;
}

.cell {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 1.5rem;
  font-weight: bold;
  text-transform: uppercase;
  background-color: var(--color-surface);
  color: var(--color-text);
}

.letter-value {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.65rem;
  line-height: 1;
  color: var(--color-letter-value);
  pointer-events: none;
}

.cell:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.cell--starter {
  background-color: var(--color-accent);
  color: var(--color-text-on-accent);
  /* Double-tap triggers the definition lookup - stop iOS's native
     text-selection callout/magnifier from appearing over it instead. */
  -webkit-touch-callout: none;
  user-select: none;
}

.cell--valid {
  background-color: var(--color-success);
  color: var(--color-text-on-accent);
}

/* Explicit color, not just background: a starter cell can simultaneously
   be part of a problem crossing word, and this must win over the starter
   rule's white text for readability against the lighter danger background.
   One colour covers every rule violation (invalid, duplicate, overused,
   floating) - the specific reason is spelled out in the "Score" display
   instead of a separate colour per rule, see getViolationMessage. */
.cell--problem {
  background-color: var(--color-danger);
  color: var(--color-text);
}

.cell--blocked {
  background-color: var(--color-dark);
}

/* A permanently unfillable cell (like a black square in a real crossword) -
   visually identical to .cell--blocked today, but a deliberately separate
   rule, since the two mean different things (structural vs "left blank at
   submit") and may want to diverge visually later. */
.cell--unusable {
  background-color: var(--color-dark);
  cursor: not-allowed;
}

.cell--starter + .letter-value,
.cell--valid + .letter-value {
  color: var(--color-text-on-accent);
}

#submit-button {
  background-color: var(--color-accent);
  color: var(--color-text-on-accent);
}

#submit-button:disabled {
  background-color: var(--color-disabled);
}

#clear-button {
  background-color: var(--color-button-bg);
  color: var(--color-text);
}

#clear-button:disabled {
  background-color: var(--color-disabled);
  color: var(--color-text-on-accent);
}

#share-button {
  background-color: var(--color-accent);
  color: var(--color-text-on-accent);
}

#share-button:disabled {
  background-color: var(--color-disabled);
}

dialog#definition-dialog,
dialog#share-dialog {
  width: min(24rem, 90vw);
  border: none;
  border-radius: 0.5rem;
  padding: 1.5rem;
}

dialog#definition-dialog::backdrop,
dialog#share-dialog::backdrop {
  background-color: var(--color-backdrop);
}

#definition-content h2 {
  margin: 0 0 0.25rem;
  text-transform: capitalize;
}

#definition-content .definition-phonetic {
  margin: 0 0 1rem;
  color: var(--color-text-muted);
  font-style: italic;
}

#definition-content .definition-part-of-speech {
  margin: 1rem 0 0.25rem;
  font-weight: bold;
  text-transform: capitalize;
}

#definition-content ol {
  margin: 0;
  padding-left: 1.25rem;
}

.definition-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

#definition-search-link {
  font-size: 0.9rem;
  color: var(--color-accent);
  text-decoration: none;
}

#definition-search-link:hover {
  text-decoration: underline;
}

dialog#definition-dialog button,
dialog#share-dialog button {
  background-color: var(--color-button-bg);
  color: var(--color-text);
}

#share-dialog h2 {
  margin: 0 0 1rem;
}

#share-preview {
  margin: 0;
  padding: 0.75rem;
  border-radius: 0.25rem;
  background-color: var(--color-bg);
  font-family: inherit;
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.share-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.share-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.share-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

#share-copy-button {
  background-color: var(--color-accent);
  color: var(--color-text-on-accent);
}
