:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #f4f1eb;
  color: #171716;
  --surface: rgba(255, 255, 252, 0.86);
  --surface-strong: #fffdf8;
  --text: #171716;
  --muted: #64605a;
  --line: rgba(23, 23, 22, 0.13);
  --stage: #11110f;
  --primary: #181917;
  --primary-text: #ffffff;
  --accent: #d96247;
  --accent-text: #ffffff;
  --shadow: 0 18px 50px rgba(45, 38, 30, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(244, 241, 235, 0.96), rgba(235, 239, 233, 0.98)),
    #f4f1eb;
  color: var(--text);
}

button,
a {
  font: inherit;
}

.app-shell {
  height: 100dvh;
  width: min(1240px, 100vw);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.view-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.view-tab.active {
  background: var(--primary);
  color: var(--primary-text);
}

.workspace {
  height: 100%;
  min-height: 0;
  display: block;
  position: relative;
}

.pane {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.workspace[data-view="camera"] .result-pane,
.workspace[data-view="result"] .camera-pane {
  display: none;
}

.pane-head {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.pane-head p {
  margin: 0;
}

.viewport {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.camera-viewport {
  background: var(--stage);
}

.result-viewport {
  box-shadow: var(--shadow);
}

.camera-feed,
.capture-canvas,
#resultImage {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.capture-canvas {
  display: none;
}

.empty-state,
.result-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}

.empty-state {
  color: rgba(255, 255, 255, 0.82);
}

.result-empty {
  color: var(--muted);
}

.empty-state p,
.result-empty p {
  margin: 0;
  font-weight: 700;
}

.camera-mark {
  width: 66px;
  height: 48px;
  border: 4px solid currentColor;
  border-radius: 8px;
  position: relative;
}

.camera-mark::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 4px solid currentColor;
  border-radius: 999px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.command-bar {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding-top: 2px;
}

.status {
  margin: 0;
  min-width: 0;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.button,
.download-link {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 22px;
  background: var(--surface-strong);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}

.button {
  min-width: 150px;
  font-weight: 800;
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.primary {
  background: var(--primary);
  color: var(--primary-text);
}

.primary.ready {
  background: var(--accent);
  color: var(--accent-text);
}

.ghost {
  background: transparent;
}

.download-link {
  min-height: 32px;
  padding: 0 14px;
  font-size: 0.88rem;
  font-weight: 700;
}

@media (prefers-color-scheme: dark) {
  :root {
    background: #121313;
    color: #f4f2ea;
    --surface: rgba(36, 36, 32, 0.92);
    --surface-strong: #1d1d1a;
    --text: #f4f2ea;
    --muted: #b5afa3;
    --line: rgba(255, 255, 255, 0.14);
    --stage: #050505;
    --primary: #f4f2ea;
    --primary-text: #141412;
    --accent: #e36b4d;
    --accent-text: #fffaf4;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
  }

  body {
    background:
      linear-gradient(135deg, rgba(19, 19, 18, 0.98), rgba(29, 31, 29, 0.98)),
      #121313;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: 100vw;
    padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
    gap: 10px;
  }

  .app-header {
    min-height: 56px;
    gap: 10px;
  }

  h1 {
    font-size: clamp(1.8rem, 9vw, 2.35rem);
  }

  .pane-head {
    height: 24px;
    font-size: 0.78rem;
  }

  .command-bar {
    min-height: 104px;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .status {
    white-space: normal;
    line-height: 1.35;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .button {
    width: 100%;
    min-height: 48px;
  }
}
