:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --paper: #fffdfa;
  --ink: #211b16;
  --muted: #756b61;
  --line: #ded3c5;
  --accent: #9e2f38;
  --gold: #b69450;
  --green: #526d5a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Yu Gothic", "YuGothic", Meiryo, system-ui, sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar,
.steps,
.workspace,
.preview-heading,
.panel-heading,
.segmented {
  display: flex;
  align-items: center;
}

.topbar {
  min-height: 72px;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.topbar div {
  text-align: center;
}

.topbar p,
.preview-heading p {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar h1,
.preview-heading h2,
.control-panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 3vw, 2.2rem);
  font-weight: 500;
}

.topbar-lead {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.84rem;
}

.back-link,
.topbar button,
.step-tab,
.primary-action,
.secondary-action,
.segmented button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
}

.back-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  text-decoration: none;
}

.topbar button {
  padding: 0 14px;
}

.steps {
  justify-content: center;
  gap: 8px;
  padding: 14px 0;
}

.step-tab {
  min-width: 112px;
  padding: 0 16px;
}

.step-tab.is-active,
.primary-action,
.segmented button.is-active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.workspace {
  align-items: stretch;
  gap: 18px;
}

.control-panel {
  flex: 0 0 310px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.upload-panel,
.settings-panel,
.preview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 18px 40px rgba(56, 43, 31, 0.08);
}

.upload-panel,
.settings-panel {
  padding: 18px;
}

.upload-box {
  display: grid;
  place-items: center;
  min-height: 156px;
  margin-top: 14px;
  border: 1px dashed #c7b89f;
  border-radius: 8px;
  background: #fbf7ef;
}

.upload-box.is-dragging {
  border-color: var(--accent);
  background: #fff1e8;
  box-shadow: 0 0 0 3px rgba(158, 47, 56, 0.12);
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-box span {
  color: var(--accent);
  font-size: 1.08rem;
  font-weight: 800;
}

.upload-box small,
.status-text,
.preview-heading span {
  color: var(--muted);
}

.status-text {
  min-height: 1.6em;
  margin: 12px 0 0;
  font-size: 0.9rem;
}

.panel-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-panel label:not(.toggle-line) {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  color: var(--muted);
  font-weight: 700;
}

.control-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.control-label output {
  min-width: 3.4em;
  color: var(--accent);
  text-align: right;
}

.settings-panel select,
.design-actions input[type="text"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--paper);
}

.settings-panel .color-control {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.color-control input[type="color"] {
  width: 58px;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.accessory-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

.accessory-controls legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.settings-panel label.accessory-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fffaf3;
}

.settings-panel label.accessory-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.accessory-toggle input {
  accent-color: var(--accent);
}

.accessory-toggle:has(input:disabled) {
  opacity: 0.46;
}

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

.primary-action {
  width: 100%;
  margin-top: 10px;
  font-weight: 800;
}

.secondary-action {
  width: 100%;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 800;
  background: #fff7f0;
}

.preview-area {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(270px, 0.68fr) minmax(420px, 1.32fr);
  gap: 18px;
  min-width: 0;
}

.preview-card {
  min-width: 0;
  padding: 16px;
}

.preview-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-heading h2 {
  font-size: 1.15rem;
  font-weight: 500;
}

.tanmono-scroll {
  height: min(72vh, 780px);
  overflow-y: auto;
  display: flex;
  justify-content: center;
  border: 1px solid #eadfce;
  border-radius: 6px;
  background: #f4ebdc;
}

canvas {
  display: block;
}

#tanmonoCanvas {
  width: min(100%, 260px);
  height: auto;
  background: #fff;
}

#kimonoCanvas {
  width: 100%;
  height: auto;
  border: 1px solid #eadfce;
  border-radius: 6px;
  background: #f8f2e8;
}

.result-guide {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  color: var(--muted);
  font-size: 0.9rem;
  background: #fff7f0;
}

.result-guide strong {
  color: var(--accent);
}

.design-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbf7ef;
}

.design-actions > label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.design-action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.design-action-buttons .primary-action,
.design-action-buttons .secondary-action {
  min-height: 44px;
  margin-top: 0;
}

.design-actions .status-text {
  margin-top: 0;
}

.model-card {
  grid-column: 2;
}

.model-card.is-deferred {
  display: none;
}

.paper-card {
  grid-column: 1 / -1;
}

#paperCanvas {
  width: min(100%, 620px);
  height: auto;
  margin: 0 auto;
  border: 1px solid #eadfce;
  border-radius: 6px;
  background: #fff;
}

.paper-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.paper-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
}

#viewer3d {
  min-height: 560px;
  height: min(72vh, 760px);
  border: 1px solid #eadfce;
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #fffdfa, #eee2d1);
}

#viewer3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#modelSelect {
  min-height: 38px;
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--paper);
}

.segmented {
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f5efe5;
}

.segmented button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 5px;
  background: transparent;
}

@media (max-width: 980px) {
  .workspace,
  .preview-area {
    display: grid;
    grid-template-columns: 1fr;
  }

  .model-card {
    grid-column: auto;
  }

  .paper-card {
    grid-column: auto;
  }

  .control-panel {
    grid-template-columns: 1fr 1fr;
    flex: none;
  }
}

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding-bottom: 12px;
  }

  .topbar div {
    text-align: left;
  }

  .steps {
    justify-content: stretch;
  }

  .step-tab {
    min-width: 0;
    flex: 1;
    padding: 0 8px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .tanmono-scroll {
    height: 58vh;
  }

  .design-action-buttons {
    grid-template-columns: 1fr;
  }

  .accessory-controls {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    background: #fff;
    overflow: hidden;
  }

  body * {
    visibility: hidden !important;
  }

  #paperCanvas {
    position: fixed;
    inset: 0;
    visibility: visible !important;
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
  }
}
