:root {
  color-scheme: dark;
  --desk: #24211e;
  --ink: #332f24;
  --ink-muted: #5c5743;
  --olive: #909176;
  --olive-light: #a2a384;
  --paper: #e4dfbb;
  --text: #eae5c7;
  --muted: #c8c2a4;
  --gold: #e6d48e;
  --jp: 'DotGothic16', 'MS Gothic', 'Yu Gothic', monospace;
  --display: 'Press Start 2P', 'Courier New', monospace;
  --paper-grain: radial-gradient(#736c4430 .6px, transparent .85px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--desk);
  background-image: radial-gradient(#b1a28616 .7px, transparent 1px);
  background-size: 4px 4px;
  color: var(--text);
  font: 16px/1.55 var(--jp);
  font-synthesis: none;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, input, textarea, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.symbol-library { display: none; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px max(24px, calc((100% - 1056px) / 2));
  border-bottom: 3px double #69664e;
  background: #302d25;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font: 15px/1.25 var(--display);
  text-shadow: 0 2px #171511;
}

.brand-number { color: #e6cc8b; }

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 6px);
  gap: 2px;
  padding: 4px;
  border: 2px solid #ada57b;
  background: #56372f;
  box-shadow: 2px 2px #161512;
}

.brand-mark i { width: 6px; height: 6px; background: #d5c497; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: #af735c; }

.header-right { display: flex; align-items: center; gap: 14px; }
.preview-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 8px;
  border: 1px solid #77745b;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: .08em;
}

.preview-label > span, .tiny-square, .status-dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  background: #bdc39a;
  box-shadow: 1px 1px #202117;
}

main { max-width: 1104px; margin-inline: auto; padding: 18px 24px 0; }

.intro-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 15px;
}

.eyebrow {
  margin: 0 0 3px;
  color: #c6bf9f;
  font: 14px/1.35 var(--jp);
  letter-spacing: .1em;
}

.eyebrow-divider { margin-inline: 3px; color: #b07b66; }

h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: .08em;
  text-shadow: 2px 2px #11100e;
}

.workshop {
  padding: 4px;
  border: 2px solid #171711;
  background: #5e5f49;
  box-shadow: inset 0 0 0 1px #96947a, 4px 5px #13120f;
}

.station-strip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 10px;
  border: 1px solid #aeac8d;
  border-bottom-color: #454537;
  background: var(--olive-light);
  color: #25271d;
}

.station-id, .form-number {
  display: inline-grid;
  place-items: center;
  min-width: 29px;
  min-height: 21px;
  border: 1px solid #3a392d;
  background: #464738;
  color: #f1e9c5;
  font: 10px/1 var(--display);
}

.station-name { font-size: 16px; line-height: 1.2; }
.station-en { font-size: 13px; letter-spacing: .08em; }
.scene-topright {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-left: auto;
  white-space: nowrap;
  font-size: 13px;
}

.scene-topright .tiny-square { background: #506143; }

.scene-wrap {
  position: relative;
  aspect-ratio: 16 / 8;
  overflow: hidden;
  border: 2px solid #211f19;
  border-top-width: 3px;
  background: #302922;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: cover;
  object-position: center bottom;
}

.scene-shade, .scene-grain { position: absolute; inset: 0; pointer-events: none; }
.scene-shade { box-shadow: inset 0 0 0 2px #1715128a; }
.scene-grain {
  background: repeating-linear-gradient(0deg, #0e0c0b15 0 1px, transparent 1px 4px);
}

.timer-overlay {
  position: absolute;
  top: clamp(12px, 2vw, 26px);
  left: clamp(12px, 2vw, 26px);
  max-width: calc(100% - 24px);
  padding: 9px 13px 8px;
  pointer-events: none;
  border: 2px solid #9d9b78;
  background-color: #25291f;
  background-image: repeating-linear-gradient(0deg, #0002 0 1px, transparent 1px 4px);
  color: #dbe3ae;
  box-shadow: inset 0 0 0 2px #141713, 3px 3px #161711bb;
}

.phase-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid #63684b;
  font-size: 14px;
  line-height: 1.15;
}

.status-dot { background: #c7d391; }
.phase-en { margin-left: auto; font-size: 12px; color: #b7be93; white-space: nowrap; }

.timer {
  margin: 12px 0 5px;
  white-space: nowrap;
  font: clamp(26px, 4.6vw, 50px)/1.08 var(--display);
  color: #e4ebac;
  text-shadow: 2px 2px #434b2d;
}

.phase-hint { margin: 4px 0 0; color: #d5d7b3; font-size: 13px; line-height: 1.4; }

body[data-phase="selling"] .timer-overlay { background-color: #382e24; border-color: #b39a6c; }
body[data-phase="selling"] .timer { color: #f0d49d; text-shadow: 2px 2px #5f4a2f; }
body[data-phase="selling"] .phase-tag, body[data-phase="selling"] .phase-en { color: #e8d4ad; }
body[data-phase="selling"] .status-dot { background: #dca86f; }
body[data-phase="paused"] .timer { color: #c7c6b2; text-shadow: 2px 2px #4b4d42; }
body[data-phase="paused"] .status-dot { background: #a5a58e; }

.scene-bottom {
  display: flex;
  align-items: center;
  gap: 10px 18px;
  min-height: 39px;
  padding: 4px 12px;
  background: #37372b;
  border: 1px solid #565743;
}

.inventory-hud, .inventory-hud strong {
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}

.inventory-hud { font-size: 14px; }
.inventory-hud > svg { color: #c4be8a; }
.inventory-hud strong { padding: 2px 7px; background: #26261d; color: #efe5b5; font-weight: 400; }
.inventory-hud strong > span { font: 13px/1.6 var(--display); }
.inventory-hud small { font-size: 11px; color: #b9b494; }
.scene-caption { color: #dad2ae; font-size: 13px; line-height: 1.4; }

.cycle-bar {
  display: flex;
  gap: 3px;
  padding: 4px;
  min-height: 34px;
  border-block: 1px solid #77765e;
  background: #4b4d3b;
}

.cycle-bar > div {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  overflow: hidden;
  padding-inline: 9px;
  border: 1px solid #2e3025;
  background: #34362a;
  color: #f0e9cb;
  font-size: 13px;
}

.cycle-production { flex: 5; }
.cycle-selling { flex: 1; min-width: 132px; }
.cycle-bar span { position: relative; }
.cycle-bar b { color: #e3d48f; font-weight: 400; margin-right: 4px; }
.cycle-bar em { margin-left: 6px; color: #e4dfbd; font-style: normal; }
#productionState { color: #e0dcc4; font-size: 12px; letter-spacing: .08em; }
.cycle-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-right: 2px solid #c0c29a;
  background: repeating-linear-gradient(90deg, #686d4e 0 6px, #5f6347 6px 8px);
  transition: width .25s linear;
}
.cycle-selling .cycle-fill {
  border-color: #dfb688;
  background: repeating-linear-gradient(90deg, #8d654c 0 6px, #805942 6px 8px);
}

.control-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 7px 10px 10px;
  border: 1px solid #a4a386;
  border-bottom-color: #414134;
  background-color: var(--olive);
  background-image: radial-gradient(#2f302435 .7px, transparent .95px);
  background-size: 4px 4px;
}

.primary-controls { display: flex; align-items: center; gap: 10px; }

.button, .icon-button, .storage-error button {
  --button-face: #575646;
  --button-hover: #68674f;
  --button-rim: #2b2b22;
  --button-light: #ffffff28;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 4px 12px;
  border: 2px solid var(--button-rim);
  background: var(--button-face);
  color: #fff3d3;
  box-shadow: inset 0 2px var(--button-light), inset 0 -3px #0003, 2px 3px #23231a;
  font-size: 15px;
  line-height: 1.35;
}

.button:hover:not(:disabled), .icon-button:hover,
.storage-error button:hover { background-color: var(--button-hover); }

.button:active:not(:disabled), .icon-button:active,
.storage-error button:active {
  transform: translate(1px, 2px);
  box-shadow: inset 0 1px var(--button-light), inset 0 -2px #0003, 1px 1px #23231a;
}

.button-primary { --button-face: #52643b; --button-hover: #5e7046; --button-rim: #292d21; }
.control-bar .button-primary { min-width: 182px; }
.button-quiet, #confirmAccept {
  --button-face: #864236;
  --button-hover: #985044;
  --button-rim: #462b25;
}
.button-quiet:disabled {
  --button-face: #63574a;
  --button-rim: #4b4738;
  color: #eee2c6;
}
.button-outlined {
  --button-face: #d1c9a3;
  --button-hover: #eee4be;
  color: var(--ink);
}

.icon-button { min-width: 38px; padding: 5px; }
.icon-button svg { width: 19px; height: 19px; }
.sound-button.active { color: #f5dd96; }
.cycle-note { margin: 0 0 0 auto; color: #1f2118; font-size: 14px; text-align: right; }

.dashboard { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 30px; }
.ledger, dialog {
  position: relative;
  min-width: 0;
  padding: 12px 14px 14px;
  border: 2px solid #93866a;
  background-color: var(--paper);
  background-image: var(--paper-grain);
  background-size: 5px 5px;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px #f1e8ca, 3px 4px #15140f;
}

.ledger::after {
  position: absolute;
  inset: auto -2px -2px auto;
  width: 13px;
  height: 13px;
  background: linear-gradient(135deg, #bfb390 0 47%, #8d8162 48% 56%, #26221b 57%);
  content: '';
}

.section-label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 8px;
  border-bottom: 3px double #797053;
  font-size: 18px;
  line-height: 1.25;
}

.form-number { border-color: #5b392f; background: #774d3e; }
.form-code { margin-left: auto; color: #605641; font-size: 12px; letter-spacing: .05em; }

.money-grid { display: grid; grid-template-columns: 1fr 1fr; padding-top: 12px; }
.money-cell { min-width: 0; padding-right: 10px; }
.money-cell + .money-cell { border-left: 1px dashed #8c8265; padding: 0 0 0 12px; }
.money-cell > p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

.money-cell > p svg { width: 14px; height: 14px; color: #774d3e; }
.money-value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 5px 0 2px;
  font: 29px/1.15 var(--jp);
  overflow-wrap: anywhere;
}
.money-value small { color: #63533f; font-size: 13px; }
.money-detail { color: var(--ink-muted); font-size: 13px; }

.text-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #8d7b58;
  background: #d6cba3;
  color: #443c2a;
  padding: 1px 5px;
  font-size: 13px;
}
.text-button:hover { background: #efe2b7; }
.text-button svg { width: 13px; height: 13px; }
.x-logo { font-family: 'Segoe UI Symbol', sans-serif; }

.session-stats {
  display: grid;
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed #897c5e;
  color: var(--ink-muted);
  font-size: 13px;
}

.session-metrics {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(0, 1fr);
  gap: 7px;
  margin: 0;
}

.session-metric {
  container-type: inline-size;
  padding: 6px 10px 8px;
  border: 1px solid color-mix(in srgb, var(--editor-paper, var(--paper)), var(--ink) 35%);
  background-color: color-mix(in srgb, var(--editor-paper, var(--paper)), var(--ink) 5%);
  background-image: var(--paper-grain);
  background-size: 5px 5px;
}

.session-metric dt {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 8px;
  flex-wrap: wrap;
  color: var(--ink-muted);
  font-size: calc(14px * var(--editor-text-scale, 1));
}

.session-metric dt small { font-size: 11px; }
.session-metric dd {
  margin: 4px 0 0;
  color: var(--ink);
  font: min(30px, calc(98cqi / var(--readout-length, 8)))/1.18 var(--display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.session-metric:last-child dd { --readout-length: 4; }
@media (max-width: 550px) {
  .session-metrics { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .session-metric-clock { grid-column: 1 / -1; }
}

.save-state { justify-self: end; white-space: nowrap; }
.save-state i { display: inline-block; width: 6px; height: 6px; margin-right: 5px; background: #516442; }

.activity-strip {
  display: flex;
  gap: 6px 12px;
  align-items: baseline;
  margin-top: 19px;
  padding: 7px 10px;
  border-block: 1px solid #726e52;
  background: #333126;
  color: #ded5b4;
  font-size: 14px;
}

.activity-title { color: #e9d48d; white-space: nowrap; font-size: 12px; }
.activity-time { margin-left: auto; color: #c6ba97; white-space: nowrap; font-size: 12px; }
footer {
  display: flex;
  justify-content: space-between;
  gap: 6px 14px;
  padding: 9px 0 17px;
  color: #bfb697;
  font-size: 12px;
}
footer i { font-style: normal; margin-inline: 4px; }
footer > span + span { letter-spacing: .08em; }

dialog {
  position: fixed;
  width: min(480px, calc(100% - 30px));
  max-height: 90vh;
  overflow: auto;
  padding: 19px;
  color-scheme: light;
  box-shadow: inset 0 0 0 2px #f1e8ca, 6px 7px #15140f;
}
dialog::backdrop { background: #191710d8; }

.share-preview-link { display: block; margin: 0 0 16px; border: 1px solid #8f8363; background: #24211e; }
.share-preview-link img { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.share-url { display: block; box-sizing: border-box; width: 100%; margin: 7px 0 10px; padding: 9px; border: 1px solid #9b9070; border-radius: 0; color: #383325; background: #eee7c7; font: 12px/1.5 monospace; }
#shareDialog .share-text-label { margin-top: 12px; }
dialog :focus-visible, .dashboard :focus-visible { outline-color: #764139; }

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  margin-bottom: 13px;
  padding-bottom: 8px;
  border-bottom: 3px double #817657;
}

.dialog-heading .eyebrow { color: #735041; }
.dialog-heading h2 { margin: 0; font-size: 22px; font-weight: 400; line-height: 1.3; }
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed #8f8363;
  cursor: pointer;
}
.setting-row strong { display: block; font-weight: 400; }
.setting-row small { display: block; color: var(--ink-muted); font-size: 14px; }

.setting-row input {
  position: relative;
  flex-shrink: 0;
  appearance: none;
  width: 36px;
  height: 21px;
  margin: 0 3px;
  border: 2px solid #5f563c;
  background: #a39975;
  cursor: pointer;
}
.setting-row input::before {
  position: absolute;
  inset: 2px auto 2px 2px;
  width: 12px;
  background: #504c3a;
  content: '';
}
.setting-row input:checked { background: #5b6b41; }
.setting-row input:checked::before { inset-inline: auto 2px; background: #f0e8be; }

.dialog-info {
  margin-top: 12px;
  padding: 8px 10px;
  border-left: 3px solid #78694c;
  background: #d2c8a2;
  font-size: 14px;
}
.dialog-small { color: var(--ink-muted); font-size: 14px; margin: 10px 0; }
.share-card {
  padding: 13px;
  margin-bottom: 12px;
  border: 1px dashed #77684c;
  background: #d7cca8;
}
.share-card .brand { color: var(--ink); text-shadow: none; }
.share-card .brand-number { color: #7c4638; }
.share-card > p { margin: 9px 0 0; font-size: 14px; }
.share-card > strong { display: block; font-size: 32px; font-weight: 400; }
.share-card small { font-size: 14px; }
.share-card > span:last-child { color: var(--ink-muted); font-size: 14px; }
.share-text-label { display: block; font-size: 14px; }
textarea {
  width: 100%;
  resize: vertical;
  padding: 8px;
  border: 1px solid #7a7054;
  background: #f0e7c4;
  color: var(--ink);
  font-size: 14px;
}
.confirm-text { color: var(--ink-muted); }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 15px; }
.import-backup { display: block; margin-top: 12px; color: var(--ink); font-size: 14px; cursor: pointer; }
.import-backup input { display: block; margin-top: 5px; max-width: 100%; font-size: 13px; }

.storage-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  margin-bottom: 12px;
  border: 2px solid #b17657;
  background: #503b2b;
}
.storage-error[hidden] { display: none; }
.storage-error button { flex-shrink: 0; }
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100% - 24px);
  padding: 7px 13px;
  border: 2px solid #4e442f;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 3px 3px #211c16;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}
#toast.visible { opacity: 1; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
.noscript { padding: 18px; color: var(--gold); }

@media (min-width: 701px) and (max-height: 800px) {
  .scene-wrap { aspect-ratio: 16 / 7.2; }
  .timer-overlay { top: 10px; padding-block: 6px; }
  .timer { margin-top: 8px; font-size: clamp(25px, 4.2vw, 44px); }
}

@media (max-width: 800px) {
  .timer-overlay { left: auto; right: clamp(6px, 2vw, 16px); max-width: 58%; }
}

@media (max-width: 700px) {
  .app-header, main { padding-inline: 15px; }
  .scene-wrap { aspect-ratio: 16 / 9; }
  .dashboard { grid-template-columns: 1fr; }
  .control-bar { flex-wrap: wrap; gap: 9px; }
  .control-bar .button-primary { min-width: 0; }
  .sound-button { order: 1; margin-left: auto; }
  .cycle-note { order: 2; width: 100%; margin: 0; text-align: left; }
}

@media (max-width: 470px) {
  .app-header { min-height: 52px; gap: 8px; padding-inline: 10px; }
  .header-right { gap: 7px; }
  .brand { font-size: 11px; gap: 8px; }
  .preview-label { padding-inline: 4px; font-size: 10px; }
  .preview-label > span { display: none; }
  main { padding: 12px 10px 0; }
  .intro-row { align-items: start; flex-wrap: wrap; }
  h1 { font-size: 27px; }
  .station-en, #productionState { display: none; }
  .timer-overlay { top: 6px; right: 6px; padding: 4px 6px; }
  .phase-tag { gap: 5px; font-size: 12px; }
  .phase-en, .phase-hint { font-size: 10px; }
  .timer { margin-top: 7px; font-size: clamp(22px, 6.7vw, 32px); }
  .scene-bottom { flex-wrap: wrap; gap: 3px; padding: 4px 6px; }
  .scene-caption { width: 100%; font-size: 12px; }
  .cycle-bar > div { padding-inline: 5px; }
  .cycle-selling { min-width: 99px; }
  .control-bar { padding-inline: 6px; }
  .control-bar .button { padding-inline: 7px; font-size: 14px; }
  .primary-controls { gap: 7px; }
  .activity-strip { flex-wrap: wrap; }
  footer { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
