﻿:root {
  color-scheme: light;
  --bg: #fff8ec;
  --surface: #fffdf8;
  --ink: #2f241c;
  --muted: #77685d;
  --line: #e7d8c3;
  --accent: #e09b24;
  --accent-dark: #8e4f12;
  --danger: #b6402a;
  --ok: #397a42;
  --shadow: 0 16px 40px rgba(97, 62, 22, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(247, 183, 51, 0.22), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(28px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 9vw, 2.4rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.status-panel,
.controls-section,
.editor-section,
.history-section {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.status-panel {
  display: grid;
  gap: 10px;
}

.status-panel > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

#totalTsp {
  font-size: 1.35rem;
}

.meter {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #f1e3cc;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f4c542, #d95f32);
  transition: width 180ms ease;
}

#statusText {
  color: var(--muted);
  font-size: 0.9rem;
}

.board-section {
  margin-top: 16px;
}

.board-frame {
  padding: clamp(6px, 2.5vw, 10px);
  border: 2px solid #4c3524;
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  aspect-ratio: 1 / 1;
  max-height: min(78vw, 430px);
  margin: 0 auto;
  touch-action: manipulation;
  border: 2px solid #3f2a1c;
  background: #fff7df;
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 3px;
  cursor: pointer;
  border: 1px dashed rgba(63, 42, 28, 0.45);
  background: rgba(255, 255, 255, 0.34);
  color: #2f241c;
  text-align: center;
}

.cell[data-filled="true"] {
  border-style: solid;
  border-color: rgba(63, 42, 28, 0.58);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.cell[data-selected="true"] {
  outline: 3px solid #2f241c;
  outline-offset: -5px;
}

.cell-label {
  display: -webkit-box;
  overflow: hidden;
  max-width: 100%;
  color: rgba(47, 36, 28, 0.84);
  font-size: clamp(0.62rem, 2.8vw, 0.88rem);
  font-weight: 800;
  line-height: 1.05;
  text-shadow: 0 1px rgba(255, 255, 255, 0.38);
  word-break: keep-all;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.rule-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.rule-row span,
.badge,
.memo-toggle {
  border-radius: 999px;
  background: rgba(224, 155, 36, 0.14);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 7px 9px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}


.piece-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.piece-actions .text-button {
  min-height: 40px;
}
.segmented,
.spice-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

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

.size-button,
.spice-button,
.ghost-button,
.text-button,
.primary-button,
.secondary-button,
.history-actions button,
.add-spice button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.size-button {
  display: grid;
  gap: 2px;
  place-items: center;
  padding: 8px 4px;
}

.size-button span {
  color: var(--muted);
  font-size: 0.75rem;
}

.size-button[aria-pressed="true"],
.spice-button[aria-pressed="true"] {
  border-color: #3f2a1c;
  background: #fff2d3;
  box-shadow: inset 0 0 0 2px rgba(63, 42, 28, 0.12);
}

.spice-button {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  padding: 9px 10px;
}

.swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 1px solid rgba(47, 36, 28, 0.28);
  border-radius: 6px;
}

.text-button,
.ghost-button {
  min-height: 36px;
  padding: 0 11px;
  background: transparent;
  color: var(--accent-dark);
}

.shape-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.add-spice {
  display: grid;
  grid-template-columns: 1fr 48px 72px;
  gap: 8px;
  margin-top: 10px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 12px;
}

input[type="color"] {
  min-height: 46px;
  padding: 4px;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.rating-row,
.save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.rating-row {
  justify-content: space-between;
  color: var(--muted);
  font-weight: 800;
}

.rating-buttons {
  display: flex;
  gap: 4px;
}

.rating-buttons button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: #bd7c0f;
  font-size: 1.1rem;
}

.rating-buttons button[aria-pressed="true"] {
  background: #ffecb6;
  border-color: #bd7c0f;
}

.primary-button,
.secondary-button {
  flex: 1;
}

.primary-button {
  border-color: #9c5c12;
  background: var(--accent);
  color: #23170f;
}

.secondary-button {
  background: #fffefa;
}

.memo-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 10px;
}

.memo-toggle input {
  width: auto;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.history-card h3 {
  font-size: 1rem;
}

.history-meta,
.history-amounts,
.history-memo {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.history-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.empty-note {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (min-width: 480px) {
  .history-card {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .history-actions {
    width: 210px;
  }
}

@media (max-width: 420px) {
  .app-header {
    padding-bottom: 10px;
  }

  h1 {
    font-size: 2rem;
  }

  .status-panel,
  .controls-section,
  .editor-section,
  .history-section {
    margin-top: 10px;
    padding: 12px;
  }

  .board-section {
    margin-top: 12px;
  }

  .rule-row span {
    font-size: 0.74rem;
    padding: 6px 8px;
  }

  .size-button,
  .spice-button,
  .primary-button,
  .secondary-button,
  .history-actions button,
  .add-spice button {
    min-height: 48px;
  }

  .spice-grid {
    gap: 7px;
  }

  .spice-button {
    padding: 9px 8px;
    font-size: 0.88rem;
  }

  .cell-label {
    font-size: clamp(0.58rem, 2.6vw, 0.78rem);
  }
}
