* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  background: #0f1117; color: #e0e0e0; min-height: 100vh;
}
header {
  background: linear-gradient(135deg, #1a1a3e, #0d2137);
  padding: 18px 24px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid #2a3a5a;
}
header h1 { font-size: 1.25em; color: #7eb8f7; font-weight: 600; }
header span { font-size: 1.6em; }
.layout { display: flex; height: calc(100vh - 62px); }
.left-panel {
  width: 56%; min-width: 320px; background: #141824;
  display: flex; flex-direction: column; border-right: 1px solid #222b40;
}
.right-panel { flex: 1; background: #10141d; display: flex; flex-direction: column; }
.panel-header {
  padding: 14px 18px; font-size: 0.8em; font-weight: 600;
  color: #5a8fc8; letter-spacing: 0.08em; text-transform: uppercase;
  background: #0f1520; border-bottom: 1px solid #1e2a40;
  display: flex; align-items: center; gap: 8px;
}
.panel-header .step {
  background: #1e4a8a; color: #a8d0ff; border-radius: 50%;
  width: 20px; height: 20px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 0.9em;
}
.canvas-area {
  flex: 1; overflow: auto; display: flex;
  align-items: center; justify-content: center;
  padding: 20px; background: #0c1018;
}
.upload-zone {
  border: 2px dashed #2a4a7a; border-radius: 16px;
  padding: 40px 40px 32px; text-align: center;
  transition: all 0.25s; width: 100%; max-width: 420px;
}
.upload-zone.drag-over { border-color: #5a9fe0; background: rgba(90,159,224,0.06); }
.upload-zone .icon { font-size: 3em; margin-bottom: 12px; }
.upload-zone .title { font-size: 1em; color: #c0d8f0; margin-bottom: 4px; cursor: pointer; }
.upload-zone .title:hover { color: #a0d0ff; }
.upload-zone .sub { font-size: 0.8em; color: #5a7a9a; }
#fileInput, #cameraFileInput { display: none; }
.upload-btns { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.canvas-wrapper {
  position: relative; display: none;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6); border-radius: 4px; overflow: hidden;
}
#imgCanvas { display: block; }
#overlay { position: absolute; top: 0; left: 0; touch-action: none; }
.toolbar {
  padding: 12px 18px; background: #0f1520;
  border-top: 1px solid #1e2a40;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.hint-text { font-size: 0.78em; color: #4a6a8a; flex: 1; min-width: 80px; }
button {
  padding: 7px 16px; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.82em; font-weight: 600; transition: all 0.18s; letter-spacing: 0.02em;
}
.btn-file  { background: #1e3a5a; color: #a0c8f0; border: 1px solid #2a4a7a; }
.btn-file:hover  { background: #264a72; }
.btn-cam   { background: linear-gradient(135deg, #1e5030, #28783e); color: #90e8a0; }
.btn-cam:hover   { filter: brightness(1.15); }
label.btn-cam { display: inline-block; cursor: pointer; padding: 7px 16px; border-radius: 6px; font-size: 0.82em; font-weight: 600; letter-spacing: 0.02em; transition: all 0.18s; }
.btn-run   { background: linear-gradient(135deg, #1e5fbb, #2e80e8); color: white; padding: 8px 20px; }
.btn-run:hover   { filter: brightness(1.15); transform: translateY(-1px); }
.btn-run:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-reset { background: #1e2a3a; color: #7a9abf; border: 1px solid #2a3a5a; }
.btn-reset:hover { background: #253444; }
.btn-new   { background: #1e2a3a; color: #7a9abf; border: 1px solid #2a3a5a; }
.btn-new:hover   { background: #253444; }
.btn-dl    { background: linear-gradient(135deg, #1a6e3a, #22a052); color: white; }
.btn-dl:hover    { filter: brightness(1.15); }
.btn-pdf   { background: linear-gradient(135deg, #7a1a1a, #c0392b); color: white; font-size: 0.9em; padding: 8px 20px; }
.btn-pdf:hover   { filter: brightness(1.15); transform: translateY(-1px); }
.output-area {
  flex: 1; overflow: auto; display: flex;
  align-items: center; justify-content: center;
  padding: 20px; background: #0c1018;
}
.output-placeholder { text-align: center; color: #2a3a50; }
.output-placeholder .big { font-size: 3em; margin-bottom: 14px; }
.output-placeholder p { font-size: 0.85em; }
#outputCanvas {
  display: none; max-width: 100%; max-height: 100%;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6); border-radius: 4px;
}
.output-toolbar {
  padding: 10px 18px; background: #0f1520;
  border-top: 1px solid #1e2a40;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.name-badge {
  display: none; align-items: center; gap: 6px;
  background: #141e30; border: 1px solid #2a3a5a;
  border-radius: 6px; padding: 4px 10px;
  font-size: 0.8em; flex: 1; min-width: 0;
}
.name-badge label { color: #5a8fc8; white-space: nowrap; }
.name-badge input {
  background: transparent; border: none; outline: none;
  color: #c0d8f0; font-weight: bold; font-size: 0.95em; width: 100%; min-width: 0;
}
.name-badge .ext { color: #4a6a8a; white-space: nowrap; }
.out-info  { font-size: 0.78em; color: #4a6a8a; }
.date-src  { font-size: 0.7em; color: #3a5a7a; white-space: nowrap; }
#processing { display: none; flex-direction: column; align-items: center; gap: 14px; color: #5a8fc8; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #1e2a3a; border-top-color: #4a8fd8;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#cameraModal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.92); z-index: 200;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
#cameraModal.open { display: flex; }
#cameraVideo {
  width: min(90vw, 640px); border-radius: 10px;
  background: #000; display: block; object-fit: cover;
}
.cam-label { font-size: 0.75em; color: #5a7a9a; letter-spacing: 0.06em; text-transform: uppercase; }
.cam-controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; }
.btn-shutter {
  width: 66px; height: 66px; border-radius: 50%;
  background: white; border: 4px solid #bbb; cursor: pointer;
  font-size: 1.7em; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 16px rgba(0,0,0,0.5); transition: transform 0.1s, background 0.1s; padding: 0;
}
.btn-shutter:hover  { background: #e0f0ff; transform: scale(1.06); }
.btn-shutter:active { transform: scale(0.92); }
.btn-flip { background: #1e2a3a; color: #7ab; border: 1px solid #2a3a5a; border-radius: 8px; padding: 9px 18px; }
.btn-flip:hover { background: #253444; }
.btn-cam-close { background: #3a1e1e; color: #e08080; border: 1px solid #5a2a2a; border-radius: 8px; padding: 9px 18px; }
.btn-cam-close:hover { background: #4a2828; }
.btn-hlmode {
  background: linear-gradient(135deg, #3a1060, #6020a0);
  color: #d8a0ff; border: 1px solid #6030a0;
}
.btn-hlmode:hover { filter: brightness(1.2); }
.btn-hlclear { background: #2a1520; color: #e08090; border: 1px solid #5a2030; }
.btn-hlclear:hover { background: #3a1a28; }
@media (max-width: 700px) {
  .layout { flex-direction: column; height: auto; }
  .left-panel, .right-panel { width: 100%; }
  .canvas-area, .output-area { min-height: 260px; }
}