:root {
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  color: #1b1f24;
  background: #edf1f5;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.app-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 22px;
  color: #fff;
  background: #202832;
  border-bottom: 1px solid #111820;
}
.app-header h1 { margin: 0; font-size: 22px; letter-spacing: .02em; }
.app-header p { margin: 2px 0 0; font-size: 12px; color: #bfc8d2; }
.status-chip {
  max-width: 48vw;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.25;
  background: #354352;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-chip.ready { background: #17613a; }
.status-chip.error { background: #8b2635; }
.status-chip.loading { background: #72590d; }

.app-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}
.sidebar {
  padding: 14px;
  overflow-y: auto;
  background: #f7f9fb;
  border-right: 1px solid #cfd6de;
}
.panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid #d8dee6;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.panel h2 { margin: 0 0 12px; font-size: 14px; }
.panel label { display: block; margin: 10px 0; font-size: 12px; font-weight: 600; color: #38414b; }
.panel select, .panel input[type="text"] {
  width: 100%;
  margin-top: 5px;
  padding: 8px 9px;
  border: 1px solid #c7d0da;
  border-radius: 6px;
  background: #fff;
  color: #1b1f24;
}
.panel input[type="range"] { width: 100%; margin: 6px 0 0; }
.panel input[type="color"] { width: 100%; height: 38px; margin-top: 5px; border: 1px solid #c7d0da; border-radius: 6px; }
output { float: right; color: #1d5f9d; font-variant-numeric: tabular-nums; }

.file-drop {
  display: grid !important;
  place-items: center;
  min-height: 92px;
  margin: 0 !important;
  border: 2px dashed #8fa1b4;
  border-radius: 8px;
  color: #2f4b67 !important;
  background: #f5f9fd;
  transition: .15s ease;
}
.file-drop.dragover { border-color: #1468ad; background: #e6f2fc; }
.file-drop input { position: absolute; opacity: 0; pointer-events: none; }
.file-drop strong { font-size: 14px; }
.file-drop span { margin-top: -12px; font-size: 11px; font-weight: 400; color: #697887; }

.image-info { margin: 10px 0 0; font-size: 11px; }
.image-info div { display: grid; grid-template-columns: 72px 1fr; gap: 6px; margin: 4px 0; }
.image-info dt { color: #687581; }
.image-info dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #bac5d0;
  border-radius: 6px;
  color: #24303c;
  background: #f6f8fa;
}
button:hover:not(:disabled) { background: #e9eef3; }
button.primary { width: 100%; color: #fff; border-color: #075a98; background: #0877bd; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #0568a6; }
button.save { min-height: 42px; margin-top: 8px; }
button.danger { color: #9f1f31; border-color: #deb8be; }
button.subtle { width: 100%; margin-top: 8px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.tool-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.tool.active { color: #fff; border-color: #0d5c96; background: #146fae; }

.small-note, .warning-note { margin: 8px 0 0; font-size: 11px; line-height: 1.5; color: #64717e; }
.warning-note { padding: 7px; color: #7a4300; border-radius: 6px; background: #fff3d9; }
.check-row { display: flex !important; align-items: center; gap: 8px; font-weight: 500 !important; }
.check-row input { margin: 0; }
.effect-options { padding-top: 2px; }
.hidden { display: none !important; }
.hidden-canvas { display: none; }

.workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  background: #3c444d;
}
.empty-state {
  align-self: center;
  justify-self: center;
  padding: 36px;
  text-align: center;
  color: #d9e0e7;
}
.empty-state h2 { margin: 10px 0 6px; font-size: 18px; }
.empty-state p { margin: 0; font-size: 12px; color: #aeb9c4; }
.empty-icon { font-size: 58px; color: #8f9ca8; }
.canvas-area {
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: grid;
  place-items: center;
}
.canvas-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: calc(100vh - 132px);
  box-shadow: 0 8px 28px rgba(0,0,0,.38);
  background: repeating-conic-gradient(#ccc 0 25%, #eee 0 50%) 50% / 18px 18px;
}
.canvas-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
#overlayCanvas { touch-action: none; }
.workspace-footer {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  color: #d7dee5;
  background: #252c33;
  border-top: 1px solid #151a1f;
  font-size: 11px;
}
#progressText { color: #91c6ec; }

@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { max-height: none; border-right: 0; border-bottom: 1px solid #cfd6de; }
  .workspace { min-height: 65vh; }
  .canvas-stage { max-height: none; }
}

@media (prefers-color-scheme: dark) {
  :root { color: #e7edf3; background: #1b2026; }
  .sidebar { background: #20262d; border-color: #39434d; }
  .panel { background: #29313a; border-color: #3d4853; }
  .panel h2, .panel label { color: #e7edf3; }
  .panel select, .panel input[type="text"] { color: #e7edf3; background: #20272f; border-color: #4c5864; }
  button { color: #e2e8ee; background: #333d47; border-color: #4b5966; }
  button:hover:not(:disabled) { background: #3e4a55; }
  .file-drop { color: #c8e5f8 !important; background: #253441; border-color: #62798e; }
  .small-note { color: #aeb8c2; }
}


.app-footer {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 14px;
  color: #687581;
  background: #f7f9fb;
  border-top: 1px solid #cfd6de;
  font-size: 11px;
}
.app-footer a { color: inherit; }
.app-footer .copyright { font-weight: 700; color: #39434d; }
.mobile-quickbar { display: none; }

@media (max-width: 900px) {
  body { padding-bottom: 62px; }
  .app-header {
    height: auto;
    min-height: 62px;
    padding: 9px 12px;
  }
  .app-header h1 { font-size: 18px; }
  .app-header p { font-size: 10px; }
  .status-chip { max-width: 45vw; font-size: 10px; }
  .app-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .workspace {
    order: 1;
    min-height: 48vh;
    height: 56vh;
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: 0 5px 18px rgba(0,0,0,.22);
  }
  .sidebar {
    order: 2;
    padding: 10px;
    overflow: visible;
  }
  .panel { padding: 12px; margin-bottom: 9px; }
  .canvas-area { padding: 8px; }
  .canvas-stage { max-height: calc(56vh - 42px); }
  .workspace-footer {
    min-height: 42px;
    padding: 6px 9px;
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
  .mobile-quickbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgba(32,40,50,.97);
    border-top: 1px solid #111820;
    backdrop-filter: blur(10px);
  }
  .mobile-quickbar button { min-height: 42px; padding: 6px 4px; font-size: 12px; }
  .app-footer { padding-bottom: 12px; }
}

@media (max-width: 520px) {
  .workspace { height: 50vh; min-height: 44vh; }
  .canvas-stage { max-height: calc(50vh - 42px); }
  .button-row { grid-template-columns: 1fr 1fr; }
  .tool-grid { grid-template-columns: 1fr 1fr; }
  .tool-grid .tool:last-child { grid-column: 1 / -1; }
  .image-info div { grid-template-columns: 66px 1fr; }
}
