:root {
  color-scheme: light;
  --ink: #252422;
  --muted: #67615d;
  --paper: #f7f2ea;
  --panel: #fffaf1;
  --line: #d8cfc2;
  --accent: #a43631;
  --accent-dark: #762821;
  --indigo: #26384d;
  --green: #5a6f54;
  --gold: #c59b43;
  font-family:
    "Inter", "Yu Gothic", "YuGothic", "Hiragino Kaku Gothic ProN", Meiryo,
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(38, 56, 77, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(38, 56, 77, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.visually-hidden-file {
  position: fixed;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(430px, 1fr);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #efe6d8;
}

.viewer-topbar {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(37, 36, 34, 0.12);
  background: rgba(255, 250, 241, 0.88);
  backdrop-filter: blur(14px);
}

.topbar-lead {
  margin-top: 8px;
  max-width: 560px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.4vw, 2.45rem);
  line-height: 1.08;
}

h2 {
  font-size: 0.98rem;
}

.quick-start {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid rgba(37, 36, 34, 0.1);
  background: rgba(255, 250, 241, 0.58);
}

.action-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border: 1px solid rgba(38, 56, 77, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.action-card.recommended {
  border-color: rgba(164, 54, 49, 0.42);
  background: #fff8ea;
  box-shadow: 0 16px 34px rgba(164, 54, 49, 0.1);
}

.action-card h2 {
  margin: 6px 0;
  font-size: 1.06rem;
}

.action-card p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--indigo);
  font-size: 0.78rem;
  font-weight: 800;
}

.recommended .step-badge {
  background: var(--accent);
}

.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.primary-link:hover {
  background: var(--accent-dark);
}

.action-controls {
  display: grid;
  gap: 8px;
  min-width: 190px;
}

.action-controls small {
  max-width: 220px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--indigo);
  border-radius: 8px;
  color: var(--indigo);
  background: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.secondary-link:hover {
  background: #f8efe1;
}

.file-link {
  position: relative;
}

.viewer-wrap,
.viewer {
  position: relative;
  min-height: 0;
}

.viewer-wrap {
  overflow: hidden;
}

.viewer {
  height: 100%;
}

.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-help {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 36px);
  padding: 10px 12px;
  border: 1px solid rgba(255, 250, 241, 0.66);
  border-radius: 8px;
  color: #fffaf1;
  background: rgba(38, 56, 77, 0.82);
  font-size: 0.86rem;
  backdrop-filter: blur(12px);
}

.viewer-help strong {
  margin-right: 4px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow: auto;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.94);
  padding: 16px;
  box-shadow: 0 16px 35px rgba(37, 36, 34, 0.08);
}

.guide-panel {
  border-color: rgba(164, 54, 49, 0.26);
  background: #fff8ea;
}

.guide-panel h2 {
  margin-bottom: 10px;
  font-size: 1.08rem;
}

.guide-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.guide-steps strong {
  color: var(--ink);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2 {
  margin-bottom: 14px;
}

.panel.compact p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.panel-note {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.panel-note + .stack-label,
.stack-label + .wide-button {
  margin-top: 12px;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.stack-label {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 6px;
}

.wide-button {
  width: 100%;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--indigo);
  border-radius: 8px;
  color: var(--indigo);
  background: #fff;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.secondary-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(164, 54, 49, 0.34);
  border-radius: 8px;
  color: var(--accent);
  background: #fff;
  font-weight: 800;
  cursor: pointer;
}

.secondary-action-button:hover {
  background: #fff4df;
}

.secondary-action-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.secondary-button:hover {
  background: #f8efe1;
}

.file-import-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.library-panel {
  border-color: rgba(38, 56, 77, 0.24);
  background: #fffaf1;
}

.upload-panel {
  display: grid;
  gap: 12px;
}

.file-drop {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 78px;
  padding: 13px;
  border: 1px dashed #b89f78;
  border-radius: 8px;
  background: #fff4df;
  cursor: pointer;
}

.file-drop:hover {
  border-color: var(--accent);
  background: #fff8ea;
}

.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  color: #fff;
  background: var(--indigo);
  font-size: 1.28rem;
}

.file-drop strong,
.file-drop small {
  display: block;
}

.file-drop small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.45;
}

#textureCanvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1e5d3;
}

label {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 38px;
  color: var(--muted);
  font-size: 0.9rem;
}

label + label {
  margin-top: 8px;
}

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

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(37, 36, 34, 0.26);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

.toggle-row {
  grid-template-columns: 20px 1fr;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.primary-button,
.return-button,
.icon-button,
.settings-toggle {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  min-height: 42px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.return-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--indigo);
  color: var(--indigo);
  background: rgba(255, 255, 255, 0.74);
  font-weight: 800;
  text-decoration: none;
}

.return-button:hover {
  background: #fff;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #fff;
  background: var(--indigo);
  font-size: 1.08rem;
}

.settings-toggle {
  display: none;
  place-items: center;
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--indigo);
  color: var(--indigo);
  background: rgba(255, 255, 255, 0.74);
  font-weight: 900;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    min-height: auto;
  }

  .quick-start {
    display: contents;
  }

  .viewer-topbar {
    order: 1;
  }

  .quick-start .action-card.recommended {
    order: 2;
    margin: 14px 14px 0;
  }

  .viewer-wrap {
    order: 3;
    min-height: 62vh;
    margin-top: 14px;
    border-top: 1px solid rgba(37, 36, 34, 0.1);
  }

  .quick-start .action-card:not(.recommended) {
    order: 4;
    margin: 14px;
  }

  .settings-toggle {
    display: inline-grid;
  }

  .controls {
    display: none;
  }

  body.settings-open .controls {
    position: fixed;
    inset: auto 12px 12px;
    z-index: 20;
    display: flex;
    max-height: min(72dvh, calc(100dvh - 96px));
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 250, 241, 0.97);
    box-shadow: 0 22px 52px rgba(37, 36, 34, 0.24);
  }
}

@media (max-width: 560px) {
  .viewer-topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

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

  .action-controls small {
    max-width: none;
  }

  label {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .button-grid {
    grid-template-columns: 1fr;
  }
}
