:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #251e18;
  --muted: #6e6256;
  --line: #d6c9b7;
  --wood: #7a422a;
  --target: #fff7c4;
  --cell: #fffaf0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid #5c2f1d;
  background: var(--wood);
  color: white;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

button.secondary,
.actions button {
  background: #fffaf0;
  color: var(--ink);
  border-color: var(--line);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 16px 40px rgb(72 49 28 / 10%);
}

.header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.4rem, 2.4vw, 2.1rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

h3 {
  margin: 0;
  font-size: 0.96rem;
}

.header p,
.hint,
.status {
  color: var(--muted);
}

.date-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
}

select,
input {
  height: 40px;
  padding: 0 10px;
}

details {
  margin-top: 14px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.hint {
  margin: 10px 0;
  font-size: 0.9rem;
}

textarea {
  min-height: 210px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.35;
  resize: vertical;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.status {
  min-height: 22px;
  margin-top: 12px;
  font-size: 0.92rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  margin-top: 18px;
}

.board-wrap,
.solutions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(46px, 1fr));
  gap: 6px;
  max-width: 820px;
  margin: 0 auto;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 62px;
  aspect-ratio: 1 / 0.78;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--cell);
  font-weight: 850;
  color: #5a2d1d;
  overflow: hidden;
}

.cell.empty {
  border: 0;
  background: transparent;
}

.cell.target {
  background: var(--target);
  border-color: #c6a13e;
  box-shadow: inset 0 0 0 2px rgb(198 161 62 / 45%);
}

.cell.covered {
  color: white;
  border-color: rgb(55 32 22 / 22%);
  text-shadow: 0 1px 1px rgb(0 0 0 / 28%);
}

.piece-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.7rem;
  color: rgb(255 255 255 / 82%);
}

.solutions {
  min-height: 360px;
}

.solutions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

#solutionCount {
  color: var(--muted);
  font-weight: 800;
}

.solution-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 620px;
  overflow: auto;
}

.solution-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  padding: 8px 10px;
  cursor: pointer;
}

.solution-item.active {
  border-color: var(--wood);
  box-shadow: inset 0 0 0 1px var(--wood);
}

.solution-item code {
  color: var(--muted);
  font-size: 0.8rem;
}

.stats-panel {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.stats-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.stats-header p {
  color: var(--muted);
  margin-top: 4px;
}

.stats-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffaf0;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.1;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin-top: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.analysis-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 14px;
  min-width: 0;
}

.analysis-card.wide {
  grid-column: 1 / -1;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(28px, 1fr));
  gap: 4px;
  margin-top: 12px;
}

.mini-cell {
  display: grid;
  place-items: center;
  min-height: 36px;
  border: 1px solid rgb(92 47 29 / 14%);
  border-radius: 4px;
  color: #2b2119;
  font-size: 0.72rem;
  font-weight: 850;
  position: relative;
  overflow: hidden;
}

.mini-cell.empty {
  border-color: transparent;
  background: transparent;
}

.mini-cell small {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.58rem;
  color: rgb(37 30 24 / 70%);
}

.bar-chart,
.habit-list,
.notes {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  font-size: 0.86rem;
}

.bar-label {
  font-weight: 850;
}

.bar-track {
  height: 12px;
  background: #efe4d4;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--wood);
}

.bar-value {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.habit-item,
.note-item {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffaf0;
  padding: 9px 10px;
}

.habit-item strong,
.note-item strong {
  color: #5a2d1d;
}

.habit-item span,
.note-item span {
  color: var(--muted);
}

@media (max-width: 860px) {
  .app {
    padding: 12px;
  }

  .header,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .date-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-header,
  .stats-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stats-controls,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board {
    grid-template-columns: repeat(9, minmax(30px, 1fr));
    gap: 4px;
  }

  .cell {
    min-height: 42px;
    font-size: 0.8rem;
  }

  .bar-row {
    grid-template-columns: 68px minmax(0, 1fr) 56px;
  }
}
