:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3347;
  --accent: #6c63ff;
  --accent2: #ff6584;
  --filled: #e2e8f0;
  --crossed: #3a3f55;
  --text: #e2e8f0;
  --text-muted: #8892b0;
  --success: #48bb78;
  --warning: #ed8936;
  --cell-size: 36px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px;
}
h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
  direction: rtl;
}
.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 32px;
  direction: rtl;
}

/* ── Setup Phase ── */
#setup-phase {
  max-width: 420px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.phase-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 20px;
  direction: rtl;
}
.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  direction: rtl;
}
.field-row label {
  font-size: 0.95rem;
  color: var(--text-muted);
  min-width: 90px;
}
.field-row input[type=number] {
  width: 80px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
.field-row input[type=number]:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 22px;
  transition: all 0.2s;
  direction: rtl;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 15px rgba(108,99,255,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(108,99,255,0.4); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-success {
  background: linear-gradient(135deg, #38a169, var(--success));
  color: #fff;
  box-shadow: 0 4px 15px rgba(72,187,120,0.3);
}
.btn-success:hover { transform: translateY(-1px); }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-danger {
  background: linear-gradient(135deg, #c53030, var(--accent2));
  color: #fff;
  box-shadow: 0 4px 15px rgba(255,101,132,0.25);
}
.btn-danger:hover { transform: translateY(-1px); }

/* ── Input Phase ── */
#input-phase { display: none; }
#solving-phase { display: none; }

.input-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Grid layout for input phase */
.grid-container {
  overflow-x: auto;
  overflow-y: auto;
  max-width: 100%;
}

/* The input grid: top-left corner empty, then col headers, then row headers + cells */
.input-grid {
  display: grid;
  gap: 2px;
}

.clue-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  text-align: center;
  outline: none;
  padding: 4px 6px;
  transition: border-color 0.2s;
  direction: ltr;
}
.clue-input:focus { border-color: var(--accent); }
.clue-input.row-clue {
  width: 110px;
  height: var(--cell-size);
}
.clue-input.col-clue {
  width: var(--cell-size);
  height: 80px;
  writing-mode: vertical-lr;
  text-orientation: mixed;
  transform: rotate(180deg);
  padding: 6px 4px;
}
.corner-cell {
  width: 110px;
  height: 80px;
  background: transparent;
}

/* Solve grid cells */
.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s;
  cursor: default;
  user-select: none;
}
.board-cell.filled {
  background: var(--filled);
  border-color: var(--filled);
  color: var(--bg);
}
.board-cell.crossed {
  background: var(--crossed);
  border-color: var(--crossed);
  color: var(--text-muted);
  font-size: 0.9rem;
}
.board-cell.highlight {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Clue label cells in solve phase */
.clue-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: 4px;
  padding: 2px 4px;
  gap: 2px;
  flex-wrap: wrap;
}
.clue-label.col-label {
  width: var(--cell-size);
  min-height: 80px;
  flex-direction: column;
}
.clue-label.row-label {
  width: 110px;
  height: var(--cell-size);
  flex-direction: row;
  justify-content: flex-end;
  gap: 4px;
}
.clue-label.done { color: #4a5568; }
.clue-num { white-space: nowrap; }

/* Controls row */
.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

/* Log panel */
#log-panel {
  width: 100%;
  max-width: 800px;
  margin: 20px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.log-header {
  padding: 12px 18px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent);
  direction: rtl;
}
#log-entries {
  padding: 14px 18px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  direction: rtl;
}
.log-entry {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.5;
  border-right: 3px solid transparent;
  direction: rtl;
}
.log-entry.info    { background: rgba(108,99,255,0.1);  border-color: var(--accent); }
.log-entry.success { background: rgba(72,187,120,0.1);  border-color: var(--success); color: var(--success); }
.log-entry.warning { background: rgba(237,137,54,0.1);  border-color: var(--warning); color: var(--warning); }
.log-entry.step    { background: rgba(108,99,255,0.07); border-color: #8b5cf6; }

.step-count {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  margin-left: 6px;
  direction: ltr;
}

/* Success banner */
#success-banner {
  display: none;
  text-align: center;
  padding: 18px;
  background: linear-gradient(135deg, rgba(72,187,120,0.15), rgba(72,187,120,0.05));
  border: 1px solid var(--success);
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--success);
  margin-top: 16px;
  direction: rtl;
}

/* Reset button area */
.top-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  direction: rtl;
  margin-top: 6px;
}

@media (max-width: 600px) {
  :root { --cell-size: 28px; }
  .clue-input.row-clue { width: 80px; }
  .clue-label.row-label { width: 80px; }
}
