:root {
  --bg: #121317;
  --panel: #1b1d24;
  --panel2: #22242c;
  --accent: #ffd54a;
  --accent2: #5ac8fa;
  --text: #eef0f4;
  --text-dim: #9aa0ab;
  --border: #2d2f38;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Helvetica Neue", Arial, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

#topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}
#topbar h1 .sub {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 8px;
}

.credit {
  flex: 1 1 auto;
  margin-left: 14px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

#statusText {
  font-size: 13px;
  color: var(--text-dim);
}

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  color: #1b1d24;
  border-color: var(--accent);
  font-weight: 600;
}
.btn.ghost { background: transparent; }

#stage {
  flex: 1 1 auto;
  display: flex;
  gap: 14px;
  padding: 14px 20px;
  min-height: 0;
}

.pane {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pane h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 8px 0;
  text-transform: none;
}

.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

#previewCanvas.draggable {
  cursor: crosshair;
  touch-action: none;
}

.hint {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
  padding: 0 20px 8px;
}

#controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 22px;
  padding: 12px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.ctrl-group select, .ctrl-group input[type="range"] {
  font-size: 14px;
}

select {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 220px;
}

input[type="range"] {
  width: 160px;
}

#gridControls label:not(:first-child) {
  margin-top: 6px;
}

.checkboxes {
  flex-direction: row;
  gap: 16px;
  align-items: center;
}
.checkboxes label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
}

.radio-row {
  display: flex;
  flex-direction: row;
  gap: 16px;
  align-items: center;
}
.radio-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.buttons {
  flex-direction: row;
  gap: 10px;
  margin-left: auto;
}

#progressWrap {
  height: 4px;
  background: var(--panel2);
  flex: 0 0 auto;
}
#progressBar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.05s linear;
}

/* ---------- スマホ（横向き）---------- */
#rotateNotice { display: none; }

/* 縦向きのスマホ：横向きにしてもらう */
@media (orientation: portrait) and (max-width: 700px) {
  #rotateNotice {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--text);
    font-size: 18px;
    text-align: center;
    padding: 24px;
  }
}

/* 高さの小さい画面（スマホ横向き）：コンパクトに詰める */
@media (max-height: 520px) {
  #app {
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #topbar { padding: 4px 12px; }
  #topbar h1 { font-size: 14px; }
  .credit { font-size: 9px; margin-left: 8px; }
  .topbar-actions { gap: 6px; }
  #statusText {
    font-size: 11px;
    max-width: 30vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .btn { padding: 5px 9px; font-size: 12px; }

  #stage { gap: 8px; padding: 6px 12px; }
  .pane h2, .hint { display: none; }

  #controls {
    gap: 6px 14px;
    padding: 6px 12px;
    max-height: 45vh;
    overflow-y: auto;
  }
  .ctrl-group { flex: 0 0 auto; font-size: 11px; }
  select { min-width: 0; padding: 4px 6px; font-size: 12px; }
  input[type="range"] { width: 110px; }
  .radio-row { gap: 10px; }
  .radio-row label, .checkboxes label { font-size: 12px; }
  .buttons { margin-left: 0; order: -1; }
}

#outputCanvas { touch-action: none; }
