/* The Quiet Trade — interface styling.
   Palette (exact, per CONTRACT.md): ink #2a2320, paper #f2e8d8,
   brass #b08343, green #5f7a5a (good), red #a4513f (bad).
   No new hues are introduced; depth comes from opacity of these five,
   never from a gradient. */

:root {
  --ink: #2a2320;
  --paper: #f2e8d8;
  --brass: #b08343;
  --good: #5f7a5a;
  --bad: #a4513f;

  --ink-05: rgba(42, 35, 32, 0.05);
  --ink-10: rgba(42, 35, 32, 0.1);
  --ink-20: rgba(42, 35, 32, 0.2);
  --ink-35: rgba(42, 35, 32, 0.35);
  --ink-60: rgba(42, 35, 32, 0.6);
  --brass-15: rgba(176, 131, 67, 0.15);
  --brass-30: rgba(176, 131, 67, 0.3);
  --brass-55: rgba(176, 131, 67, 0.55);
  --paper-70: rgba(242, 232, 216, 0.7);
  --good-15: rgba(95, 122, 90, 0.15);
  --bad-15: rgba(164, 81, 63, 0.15);

  --font-hand: Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  /* belt-and-suspenders: every element below is also sized to fit a 360px
     viewport on its own, but this guarantees no stray control can ever
     force a horizontal scrollbar. */
  overflow-x: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.45;
  min-height: 100vh;
}

h1,
h2,
h3,
.hand {
  font-family: var(--font-hand);
}

a {
  color: var(--ink);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1rem 3rem;
}

/* ---------- focus ---------- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--brass);
  outline-offset: 2px;
}

/* fallback for browsers without :focus-visible support */
a:focus,
button:focus,
input:focus,
select:focus {
  outline: 3px solid var(--brass);
  outline-offset: 2px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.5rem;
}

.topbar h1 {
  margin: 0.2rem 0;
  font-size: 1.5rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

.stats .stat {
  white-space: nowrap;
}

.stat-label {
  color: var(--ink-60);
  margin-right: 0.25em;
}

/* ---------- save bar ---------- */

.save-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--ink-20);
  margin-bottom: 0.75rem;
}

#save-status {
  min-height: 1.2em;
  color: var(--ink-60);
}

#save-status[data-state="error"] {
  color: var(--bad);
  font-weight: bold;
}

#save-status[data-state="ok"] {
  color: var(--good);
}

.save-bar .spacer {
  flex: 1 1 auto;
}

/* ---------- buttons ---------- */

button {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  min-height: 2.5rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--brass-15);
}

button:active:not(:disabled) {
  background: var(--brass-30);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  border-color: var(--ink-35);
}

button.primary {
  background: var(--brass);
  border-color: var(--ink);
  font-weight: bold;
}

button.primary:hover:not(:disabled) {
  background: var(--brass-55);
}

button.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  min-height: 2.25rem;
}

button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

button.danger:hover:not(:disabled) {
  background: var(--bad-15);
}

input[type="number"],
input[type="text"],
select {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink-35);
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
  max-width: 100%;
  min-height: 2.25rem;
}

/* nothing interactive may be wider than its row — a long disabledReason
   string in an <option> must not be able to push the page wide */
button,
select {
  max-width: 100%;
}

label {
  font-size: 0.85rem;
}

/* ---------- status / message line ---------- */

#status-line {
  min-height: 1.4em;
  margin: 0.5rem 0;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

#status-line:empty {
  display: none;
}

#status-line[data-ok="true"] {
  background: var(--good-15);
  color: var(--good);
  border: 1px solid var(--good);
}

#status-line[data-ok="false"] {
  background: var(--bad-15);
  color: var(--bad);
  border: 1px solid var(--bad);
}

/* ---------- scene ---------- */

.scene-wrap {
  position: relative;
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper);
  margin-bottom: 1rem;
}

#scene {
  display: block;
  width: 100%;
  height: auto;
}

.win-pane {
  transition: fill 0.4s ease;
}

.win-glow {
  transition: opacity 0.4s ease;
}

.flame {
  transform-origin: 50% 100%;
}

@media (prefers-reduced-motion: no-preference) {
  .flame {
    animation: flicker 2.6s ease-in-out infinite;
  }
}

@keyframes flicker {
  0%,
  100% {
    transform: scaleY(1) scaleX(1) rotate(0deg);
  }
  20% {
    transform: scaleY(1.06) scaleX(0.96) rotate(-1deg);
  }
  45% {
    transform: scaleY(0.94) scaleX(1.04) rotate(1deg);
  }
  70% {
    transform: scaleY(1.03) scaleX(0.98) rotate(-0.5deg);
  }
}

.bin {
  transition: fill-opacity 0.3s ease;
}

/* peek affordance — small and easy to miss, never invisible or hover-only.
   Small and easy to overlook: the visible
   mark stays tiny (14px ring), but the tappable/clickable hit area is a
   full 44px so it works as a real touch target. Discoverable at rest
   (opacity 0.4, not near-zero) so a touch user who cannot hover still
   finds it by looking or by tabbing to it with a keyboard. */
.peek-affordance {
  position: absolute;
  top: 6%;
  right: 9%;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.peek-affordance::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--ink-35);
  background: transparent;
  opacity: 0.4;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.peek-affordance:hover::before,
.peek-affordance:focus-visible::before,
.peek-affordance:active::before {
  opacity: 1;
  background: var(--paper-70);
}

/* ---------- screens ---------- */

.screen[hidden] {
  display: none;
}

.screen {
  display: block;
}

.panel {
  border: 1px solid var(--ink-35);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--paper);
}

.panel > h2,
.panel > h3 {
  margin-top: 0;
}

/* ---------- day screen ---------- */

.day-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 760px) {
  .day-grid {
    grid-template-columns: 1fr 1fr;
  }
  .panel.slate-panel {
    grid-column: 1 / -1;
  }
}

.slate-panel {
  border-color: var(--ink);
  border-width: 2px;
}

.slate-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slate-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  border: 1px solid var(--ink-35);
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  background: var(--paper);
}

.slate-item .slate-index {
  font-family: var(--font-hand);
  color: var(--ink-60);
  min-width: 1.4em;
}

.slate-item .slate-text {
  flex: 1 1 12rem;
  min-width: 0;
  overflow-wrap: break-word;
}

.slate-item.invalid {
  border-color: var(--bad);
  background: var(--bad-15);
}

.slate-item .slate-warning {
  color: var(--bad);
  font-size: 0.85rem;
  flex-basis: 100%;
}

.slate-item .slate-controls {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* Reordering is the core interaction on a touch screen — these buttons get
   a real tap target (>= 44px per side, the standard minimum) even though
   they carry the same .small class as other compact buttons elsewhere. */
.slate-controls button {
  min-height: 2.75rem;
  min-width: 2.75rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
}

.slate-empty {
  color: var(--ink-60);
  font-style: italic;
}

.add-order-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  border-top: 1px dashed var(--ink-20);
  padding-top: 0.5rem;
  margin-top: 0.4rem;
}

.add-order-row select {
  flex: 1 1 10rem;
  min-width: 0;
}

.add-order-row:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.lock-up-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.list-plain {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--ink-10);
}

.row:last-child {
  border-bottom: none;
}

.row .row-name {
  flex: 1 1 8rem;
  min-width: 0;
  overflow-wrap: break-word;
}

.row .row-detail {
  color: var(--ink-60);
  font-size: 0.85rem;
  flex-basis: 100%;
}

.qty-input {
  width: 4rem;
}

.commission-card {
  border: 1px solid var(--ink-35);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
}

.commission-card.status-done {
  border-color: var(--good);
  background: var(--good-15);
}

.commission-card.status-failed {
  border-color: var(--bad);
  background: var(--bad-15);
}

.commission-card .blurb {
  font-style: italic;
  color: var(--ink-60);
  font-size: 0.9rem;
}

/* ---------- morning screen ---------- */

.morning-headline {
  font-size: 1.3rem;
  border-left: 4px solid var(--brass);
  padding-left: 0.6rem;
  margin: 0.25rem 0 1rem;
}

.night-log {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.night-log .folk-heading {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  margin: 0.9rem 0 0.3rem;
  color: var(--ink);
}

.night-log .folk-heading:first-child {
  margin-top: 0;
}

.log-line {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  padding: 0.15rem 0 0.15rem 0.6rem;
  border-left: 3px solid transparent;
}

.log-line.tone-good {
  color: var(--good);
  border-left-color: var(--good);
}

.log-line.tone-bad {
  color: var(--bad);
  border-left-color: var(--bad);
}

.log-line.tone-neutral {
  color: var(--ink);
  border-left-color: var(--ink-20);
}

/* A line the folk never reached — shown struck through and quiet, in its
   actual place in the account, rather than in a separate recap. Seeing the
   instruction that never ran, where it would have run, is the teaching
   moment; a duplicate appendix would just repeat the same sentence. */
.log-line.unreached {
  color: var(--ink-35);
  text-decoration: line-through;
  border-left-color: transparent;
  font-style: italic;
}

.produced-block {
  margin: 0.5rem 0 1rem;
}

.produced-block h3 {
  font-size: 0.95rem;
  color: var(--ink-60);
  margin: 0 0 0.3rem;
  font-family: var(--font-ui);
  font-weight: normal;
  font-style: italic;
}

.note-paper {
  background: var(--brass-15);
  border: 1px solid var(--brass);
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  margin: 1rem 0;
  font-family: var(--font-hand);
  font-size: 1.05rem;
  font-style: italic;
}

.advice-line {
  color: var(--ink-60);
  font-size: 0.9rem;
  font-style: italic;
  margin: 0.5rem 0 1rem;
}

.morning-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ---------- dialog ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--ink-60);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  max-width: 30rem;
  width: 100%;
}

.dialog h2 {
  margin-top: 0;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.dialog-actions button {
  min-height: 2.75rem;
}

/* ---------- import error / banners ---------- */

.import-error,
.recovery-banner {
  border: 1px solid var(--bad);
  background: var(--bad-15);
  color: var(--bad);
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  margin: 0.75rem 0;
}

.import-error[hidden],
.recovery-banner[hidden] {
  display: none;
}

.recovery-banner .banner-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- small utility ---------- */

fieldset {
  border: 1px solid var(--ink-20);
  border-radius: 4px;
  margin: 0 0 0.75rem;
}

legend {
  font-family: var(--font-hand);
  padding: 0 0.4rem;
}

@media (max-width: 420px) {
  .topbar h1 {
    font-size: 1.2rem;
  }
  .stats {
    font-size: 0.85rem;
  }
}
