:root {
  color-scheme: light;
  --paper: #f7f4ee;
  --ink: #24231f;
  --muted: #6f6b62;
  --hairline: rgba(36, 35, 31, 0.16);
  --surface: #fbf8f1;
  --field: #f8f5ef;
  --flow: #466f73;
  --flow-soft: rgba(70, 111, 115, 0.18);
  --object: rgba(151, 116, 78, 0.16);
  --object-line: #8d7356;
  --accent: #9b653d;
  --focus: #286f76;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 4vw, 48px) 10px;
  border-bottom: 1px solid var(--hairline);
}

.identity {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  letter-spacing: 0;
}

.series,
.version,
.language-label,
.credit,
.title-group p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--hairline);
}

.title-group {
  min-width: 0;
}

h1,
.title-group p {
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 2.4vw, 2rem);
  font-weight: 520;
  line-height: 1;
}

.title-group p {
  margin-top: 4px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-select,
select,
button {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
}

select {
  min-height: 34px;
  border-radius: 6px;
  padding: 4px 28px 4px 10px;
}

.icon-button,
.dialog-close {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
}

.icon-button span {
  font-family: Georgia, serif;
  font-size: 1rem;
}

.stage {
  min-height: 0;
  display: grid;
  place-items: stretch;
  padding: clamp(14px, 2.4vw, 28px) clamp(14px, 4vw, 48px);
  overflow: hidden;
}

.canvas-panel {
  position: relative;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--hairline);
  background: var(--field);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  cursor: grab;
}

canvas.is-dragging {
  cursor: grabbing;
}

.readout {
  position: absolute;
  left: clamp(14px, 2vw, 24px);
  bottom: clamp(14px, 2vw, 24px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  max-width: min(760px, calc(100% - 28px));
  padding: 9px 12px;
  color: var(--muted);
  background: rgba(251, 248, 241, 0.9);
  border: 1px solid rgba(36, 35, 31, 0.1);
  font-size: 0.78rem;
}

.readout strong {
  color: var(--ink);
  font-weight: 520;
  margin-left: 5px;
}

.control-area {
  border-top: 1px solid var(--hairline);
  padding: 12px clamp(14px, 4vw, 48px) 14px;
}

.control-bar {
  display: grid;
  grid-template-columns: minmax(170px, 0.95fr) minmax(190px, 1fr) minmax(170px, 0.95fr) auto;
  gap: 12px;
  align-items: stretch;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 8px 10px 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(251, 248, 241, 0.62);
}

legend {
  padding: 0 5px;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 600;
}

label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.guide-summary,
.guide-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 22px;
  color: var(--muted);
  font-size: 0.76rem;
}

.guide-summary strong,
.guide-toggle strong {
  color: var(--ink);
  font-weight: 520;
}

.guide-toggle input {
  width: 14px;
  height: 14px;
  margin-left: auto;
  accent-color: var(--focus);
}

.guide-toggle input:disabled {
  accent-color: var(--hairline);
}

fieldset select {
  width: 100%;
  margin-top: 7px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--focus);
}

output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.reset-button {
  align-self: stretch;
  min-width: 86px;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 520;
  background: var(--surface);
}

.credit {
  margin: 10px 0 0;
  text-align: right;
}

.info-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 24px;
  box-shadow: 0 18px 60px rgba(36, 35, 31, 0.18);
}

.info-dialog::backdrop {
  background: rgba(36, 35, 31, 0.24);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.info-dialog h2 {
  margin: 0 34px 12px 0;
  font-size: 1.2rem;
  font-weight: 560;
}

.info-dialog p {
  color: var(--muted);
  line-height: 1.55;
}

.info-dialog ul {
  margin: 8px 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.5;
}

.info-dialog li {
  margin: 4px 0;
}

.info-subhead {
  margin-bottom: 6px;
  color: var(--ink) !important;
  font-weight: 560;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .control-bar {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .reset-button {
    min-height: 44px;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    gap: 12px;
    padding-top: 12px;
  }

  .identity {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .language-label {
    display: none;
  }

  .stage {
    padding: 10px;
  }

  .control-area {
    padding: 10px;
  }

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

  .reset-button {
    grid-column: span 2;
  }
}

@media (orientation: portrait) and (max-width: 520px) {
  .app-shell {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .stage {
    overflow: visible;
  }

  .canvas-panel {
    height: 54svh;
    min-height: 320px;
  }

  .readout {
    position: static;
    margin: 8px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .topbar {
    min-height: 46px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  h1 {
    font-size: 1.24rem;
  }

  .title-group p {
    margin-top: 2px;
    font-size: 0.68rem;
  }

  .stage {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .control-area {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .control-bar {
    grid-template-columns: minmax(120px, 0.8fr) minmax(170px, 1fr) minmax(120px, 0.8fr) minmax(78px, 0.45fr);
    gap: 6px;
  }

  fieldset {
    padding: 3px 8px 4px;
  }

  legend,
  label {
    font-size: 0.7rem;
  }

  select {
    min-height: 26px;
    margin-top: 3px;
  }

  input[type="range"] {
    margin: 0;
  }

  .readout {
    bottom: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
    gap: 6px 11px;
    padding: 6px 8px;
    font-size: 0.72rem;
  }

  .readout strong {
    margin-left: 4px;
  }

  .reset-button {
    min-width: 0;
    padding: 0 10px;
    grid-column: auto;
  }

  .credit {
    margin-top: 5px;
  }

  .info-dialog {
    padding: 18px;
  }
}
