/* COACH — Killer Sudoku Coaching App */

/* Enforce the semantic meaning of [hidden] against any display rules below */
[hidden] { display: none !important; }

:root {
  --bg:           #111827;
  --surface:      #1f2937;
  --surface-2:    #374151;
  --border:       #374151;
  --accent:       #e94560;
  --accent-dim:   #9b1c31;
  --text:         #f3f4f6;
  --text-muted:   #9ca3af;
  --success:      #34d399;
  --error:        #f87171;
  --input-bg:     #111827;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 2rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.btn-quit {
  margin-left: auto;
  font-size: 0.75rem;
  padding: 0.35rem 0.9rem;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.header-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Main layout ── */

main {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Card ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.card h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Form elements ── */

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

select,
input[type="file"] {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.7rem;
  border-radius: 5px;
  font-size: 0.875rem;
  max-width: 280px;
}

select:focus {
  outline: 2px solid var(--accent-dim);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

/* ── Buttons ── */

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1.25rem;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: opacity 0.15s;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button:hover:not(:disabled) {
  opacity: 0.82;
}

/* ── Status message ── */

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

.status.error {
  color: var(--error);
}

/* ── Review panel: images side by side ── */

#images-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 2rem;
  align-items: start;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}

.image-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}

#review-actions {
  margin-bottom: 1rem;
}

/* ── Grid canvas ── */

#canvas-wrapper {
  position: relative;
  display: inline-block;
}

#grid-canvas {
  display: block;
  border-radius: 3px;
  border: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
}

#cage-total-edit {
  position: absolute;
  display: none;
  width: 50px;
  height: 50px;
  font-size: 26px;
  font-weight: bold;
  text-align: center;
  padding: 0;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  box-sizing: border-box;
  z-index: 10;
}

/* ── Original photo and warped grid images ── */

#original-img,
#warped-img {
  display: block;
  max-width: 458px;
  width: 100%;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ── Digit pad (mobile entry) ── */

.digit-pad {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
  max-width: 330px;
}

.digit-btn {
  width: 3rem;
  height: 3rem;
  font-size: 1.2rem;
  font-weight: 600;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.digit-btn:hover:not(:disabled) {
  background: var(--border);
}

.digit-clear {
  color: var(--error);
}

/* ── Secondary button variant ── */

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
  opacity: 1;
}

/* ── Cage editor ── */

.hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.puzzle-type-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
}

/* ── Solution grid ── */

.solution-table {
  border-collapse: collapse;
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.solution-table td {
  width: 2.25rem;
  height: 2.25rem;
  text-align: center;
  border: 1px solid var(--border);
  color: var(--text);
}

.solution-table td.box-bottom {
  border-bottom: 2px solid var(--text-muted);
}

.solution-table td.box-right {
  border-right: 2px solid var(--text-muted);
}

/* ── Playing mode ── */

#playing-actions {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  margin-top: 0.25rem;
}

/* ── Cage solutions inspector ── */

#cage-inspector {
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.soln-item {
  display: block;
  padding: 0.2rem 0;
  line-height: 1.6;
}

.soln-item.active {
  color: var(--text);
  cursor: pointer;
}

.soln-item.active:hover {
  color: var(--accent);
}

.soln-item.user-eliminated {
  text-decoration: line-through;
  color: var(--text-muted);
  cursor: pointer;
}

.soln-item.user-eliminated:hover {
  color: var(--text);
}

.soln-item.auto-impossible {
  opacity: 0.35;
  cursor: default;
}

/* ── Virtual cage panel ── */

#virtual-cage-col {
  min-width: 180px;
  max-width: 260px;
}

#vc-form {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.vc-item {
  margin-bottom: 1.25rem;
}

.vc-item-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.vc-solutions {
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
}

/* ── Responsive / Mobile ── */

@media (max-width: 620px) {
  header {
    padding: 0.625rem 1rem;
  }

  /* Wrap header buttons so they don't push off-screen */
  .header-inner {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Hide descriptive subtitle — save horizontal space */
  .header-sub {
    display: none;
  }

  main {
    margin: 0.75rem auto;
    padding: 0 0.75rem;
    gap: 1rem;
  }

  .card {
    padding: 1rem;
  }

  /* Stack reference images vertically instead of forcing horizontal scroll */
  #images-row {
    flex-direction: column;
    overflow-x: unset;
  }

  /* Action bar wraps onto multiple rows so no button is clipped */
  .form-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Increase tap targets to the Apple HIG 44 pt minimum */
  button {
    min-height: 44px;
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
  }

  /* Digit buttons already close to 44px (3rem); nudge up slightly */
  .digit-btn {
    width: 3.25rem;
    height: 3.25rem;
    font-size: 1.25rem;
  }

  /* Digit pad can use full card width on narrow screens */
  .digit-pad {
    max-width: none;
  }

  /* Reference images should not overflow card width */
  #original-img,
  #warped-img {
    max-width: 100%;
  }

  /* Allow image columns to shrink below their content size */
  .image-col {
    flex-shrink: 1;
    min-width: 0;
  }

  /* Canvas wrapper: block so the canvas fills its column width */
  #canvas-wrapper {
    display: block;
    width: 100%;
  }

  /* Scale the canvas to fit the column — the click handler already applies
     (canvas.width / rect.width) so coordinates remain correct. */
  #grid-canvas {
    width: 100%;
    aspect-ratio: 1;
  }

  /* Canvas column appears last in the HTML (after the reference photos) so that
     on desktop the reading order is: original → warped → detected. On mobile the
     flex column would put it last, so use order to hoist it to the top. */
  #canvas-col { order: -1; }
  #original-col, #warped-col { order: 0; }
}

#version-banner {
  position: fixed;
  bottom: 0.4rem;
  right: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.5;
  user-select: text;
  z-index: 9999;
}

/* ── Dialog / modal base ── */

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 540px;
  width: 90vw;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

/* ── Hints dropdown ── */

.hints-anchor {
  position: relative;
}

.hints-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 260px;
  max-width: 380px;
  padding: 0.35rem 0;
  overflow: hidden;
}

.hint-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.55rem 1rem;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  line-height: 1.4;
}

.hint-item:hover {
  background: var(--surface-2);
  opacity: 1;
}

.hints-empty {
  padding: 0.6rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

/* ── Hint explanation modal ── */

#hint-modal {
  max-width: 520px;
  width: 90vw;
}

/* Config modal — rule list */
.config-rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.25rem 0;
  min-width: 340px;
}

.config-rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.config-rule-name {
  font-size: 0.9rem;
  flex: 1;
}

.config-rule-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-rule-info {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--accent);
  padding: 0 0.25rem;
  line-height: 1;
}
.btn-rule-info:hover { opacity: 0.7; }

.hint-modal-explanation {
  margin: 1rem 0 0.5rem;
  line-height: 1.6;
  font-size: 0.9rem;
}

.hint-modal-summary {
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
