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

html {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f0f4f8;
  color: #1e293b;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ── Header ── */
header {
  position: relative;
  text-align: center;
  padding: 10px 16px 8px;
  background: #2563eb;
  color: white;
  flex-shrink: 0;
}

#btn-settings {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.85;
}

#btn-settings:active {
  opacity: 1;
}

header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
}

#level-indicator,
#theme-indicator {
  pointer-events: none;
}

#level-indicator {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 1px;
}

#theme-indicator {
  font-size: 13px;
  opacity: 0.7;
  margin-top: 1px;
  font-style: italic;
}

/* ── Word List ── */
#word-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 6px;
  padding: 8px 10px 4px;
  flex-shrink: 0;
}

.word-tag {
  font-size: 18px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 10px;
  text-align: center;
  background: #e2e8f0;
  color: #334155;
  transition: all 0.3s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.word-tag:active {
  background: #cbd5e1;
}

.word-tag.found {
  background: #bbf7d0;
  color: #166534;
  text-decoration: line-through;
  cursor: default;
}

button:focus-visible, .word-tag:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

/* ── Quote Display ── */
#quote-display {
  flex-shrink: 0;
  padding: 0 10px 4px;
}

#quote-author {
  background: #dc2626;
  color: white;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 6px 12px;
  border-radius: 10px 10px 0 0;
}

#quote-text {
  background: white;
  padding: 10px 14px;
  font-size: 17px;
  line-height: 1.6;
  color: #334155;
  border-radius: 0 0 10px 10px;
  border: 1px solid #e2e8f0;
  border-top: none;
}

.quote-blank {
  display: inline-block;
  border-bottom: 2.5px solid #475569;
  min-width: 40px;
  text-align: center;
  font-weight: 700;
  color: transparent;
  padding: 0 2px;
  margin: 0 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  vertical-align: baseline;
}

.quote-blank.found {
  color: #16a34a;
  border-bottom-color: #16a34a;
  cursor: default;
  font-weight: 700;
}

/* ── Grid ── */
#grid-container {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10px 6px 6px;
  overflow: hidden;
}

#grid-wrapper {
  position: relative;
  width: min(88vw, calc(100vh - 280px), 500px);
  height: min(88vw, calc(100vh - 280px), 500px);
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 8), 1fr);
  grid-template-rows: repeat(var(--grid-size, 8), 1fr);
  gap: 2px;
  width: 100%;
  height: 100%;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4.5vw, 28px);
  font-weight: 700;
  background: white;
  border-radius: 6px;
  color: #1e293b;
  transition: background 0.15s, color 0.15s;
}

.cell.selecting {
  background: #bfdbfe;
  color: #1e40af;
}

.cell.found-cell {
  background: #bbf7d0;
  color: #166534;
}

.cell.hint-flash {
  background: #fde68a;
  color: #92400e;
  transition: background 0.1s;
}

/* ── Navigation Bar ── */
#nav-bar {
  display: flex;
  gap: 12px;
  padding: 14px 16px 12px;
  justify-content: center;
  flex-shrink: 0;
}

#nav-bar button {
  flex: 1;
  max-width: 180px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, opacity 0.15s;
}

#btn-prev {
  background: #e2e8f0;
  color: #475569;
}

#btn-prev:active:not(:disabled) {
  background: #cbd5e1;
}

#btn-prev:disabled {
  opacity: 0.4;
  cursor: default;
}

#btn-next {
  background: #2563eb;
  color: white;
}

#btn-next:active {
  background: #1d4ed8;
}

/* ── Completion overlay ── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 10;
}

#overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

body:has(#overlay.visible) #nav-bar {
  pointer-events: none;
}

#overlay .message {
  background: white;
  border-radius: 16px;
  padding: 32px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

#overlay .message h2 {
  font-size: 28px;
  color: #16a34a;
  margin-bottom: 8px;
}

#overlay .message p {
  font-size: 18px;
  color: #64748b;
}

/* ── Dialogs (confirm + hint) ── */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}

.dialog-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.dialog-box {
  background: white;
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  min-width: 260px;
}

.dialog-box p {
  font-size: 18px;
  color: #334155;
  margin-bottom: 20px;
}

.dialog-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.dialog-buttons button {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#confirm-no, #hint-no {
  background: #e2e8f0;
  color: #475569;
}

#confirm-yes, #hint-yes {
  background: #2563eb;
  color: white;
}

/* ── Highlight lines (SVG overlay) ── */
#highlight-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

#highlight-svg line {
  stroke-linecap: round;
}

/* ── Settings dialog ── */
#settings-dialog .dialog-box h3 {
  font-size: 20px;
  color: #334155;
  margin-bottom: 16px;
}

#size-options {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 80px;
}

.size-btn {
  flex: 1;
  padding: 12px 8px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.size-btn.selected {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}

#settings-cancel {
  background: #e2e8f0;
  color: #475569;
}

#settings-ok {
  background: #2563eb;
  color: white;
}

/* ── Word tag sizing for smaller grids ── */
body[data-grid-size="6"] .word-tag,
body[data-grid-size="7"] .word-tag {
  font-size: 22px;
  padding: 6px 8px;
}

/* ── Update button & version tag ── */
#btn-update {
  position: fixed;
  bottom: 4px;
  left: 6px;
  font-size: 10px;
  color: #94a3b8;
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  z-index: 5;
}

#btn-update:active {
  color: #475569;
}

#version {
  position: fixed;
  bottom: 6px;
  right: 6px;
  font-size: 10px;
  color: #94a3b8;
  pointer-events: none;
}
