:root {
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  font-size: 16px;
  color: var(--paper-ink, #3d3223);
  background: var(--paper-inset, #eee3ca);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, select, input { font: inherit; }
button, select {
  min-height: 46px;
  border: 1px solid var(--paper-border, #c5b28c);
  border-radius: 12px;
  color: inherit;
  background: var(--paper-raised, #fffaf0);
  padding: 8px 14px;
}
button { cursor: pointer; font-weight: 700; }
button:hover:not(:disabled) { border-color: var(--paper-gold, #80560f); }
button:disabled, select:disabled, input:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--paper-action, #315a48); color: #fffaf0; }
:focus-visible { outline: 3px solid var(--paper-gold, #80560f); outline-offset: 3px; }
p { margin: 0; line-height: 1.5; }
.editor {
  width: min(100%, 1040px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
}
.heading { display: flex; align-items: center; gap: 18px; margin-bottom: 8px; }
h1 { margin: 0; font-size: clamp(26px, 3vw, 36px); letter-spacing: .06em; }
.local-tag { padding: 4px 10px; border: 1px solid var(--paper-border, #c5b28c); border-radius: 20px; white-space: nowrap; }
.editor-header p, .drag-help, .zoom-help { color: var(--paper-muted, #706047); }
.mobile-break { display: none; }
.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 26px;
  padding: 24px;
  border: 1px solid var(--paper-border, #c5b28c);
  border-radius: 24px;
  background: var(--paper-surface, #fbf5e6);
  box-shadow: var(--paper-shadow, 0 5px 18px rgba(55, 39, 13, .19));
}
.preview-panel { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 14px; }
.preview-space { min-height: 0; display: grid; place-items: center; container-type: size; }
.portrait-viewport {
  position: relative;
  width: min(100cqw, 100cqh, 420px);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--paper-inset, #eee3ca);
  outline: 2px solid var(--paper-border, #c5b28c);
  box-shadow: 0 6px 20px rgba(55, 39, 13, .12);
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.portrait-viewport:focus-visible { outline: 3px solid var(--paper-gold, #80560f); outline-offset: 4px; }
.portrait-viewport.dragging { cursor: grabbing; }
.portrait-viewport[aria-disabled="true"] { cursor: default; }
.portrait-viewport img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.portrait-fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(22px, 5vw, 42px); font-weight: bold; }
.drag-help { text-align: center; text-wrap: balance; }
.controls-panel { align-self: center; display: grid; gap: 28px; min-width: 0; }
.field { display: grid; gap: 8px; }
label { font-weight: 700; }
select { width: 100%; min-width: 0; }
.zoom-label { display: flex; justify-content: space-between; align-items: center; }
output { font-size: 24px; font-weight: 700; color: var(--paper-gold, #80560f); font-variant-numeric: tabular-nums; }
input[type="range"] { display: block; width: 100%; height: 38px; margin: 0; accent-color: var(--paper-action, #315a48); cursor: pointer; }
.file-actions { display: flex; justify-content: center; gap: 12px; }
.file-actions button { min-width: 160px; }
.editor-status { min-height: 48px; max-width: 760px; margin: 8px auto 0; text-align: center; text-wrap: balance; overflow-wrap: anywhere; }
.editor-status.error { color: var(--paper-danger, #a3382b); }

@media (max-width: 640px) {
  .editor { padding: max(12px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom)); gap: 10px; }
  .heading { justify-content: space-between; gap: 6px; margin-bottom: 6px; }
  h1 { font-size: 26px; }
  .local-tag { padding: 3px 8px; }
  .mobile-break { display: initial; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; padding: 12px; gap: 12px; border-radius: 18px; }
  .preview-panel { gap: 8px; }
  .drag-help { font-size: 16px; line-height: 1.3; }
  .controls-panel { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; align-items: end; }
  .field { gap: 4px; }
  .zoom-field { grid-column: 1 / -1; grid-row: 2; }
  .zoom-help { font-size: 16px; line-height: 1.3; }
  .file-actions { gap: 10px; }
  .file-actions button { flex: 1; min-width: 0; }
  .editor-status { margin-top: 6px; line-height: 1.35; min-height: 44px; }
}
@media (min-width: 641px) and (max-height: 650px) {
  .editor { padding-top: 12px; padding-bottom: 10px; gap: 10px; }
  .workspace { padding: 16px; }
  .controls-panel { gap: 12px; }
}
