:root {
  --bg: #0e1320;
  --bg-2: #161d2e;
  --panel: #1b2336;
  --panel-2: #222c44;
  --line: #2c3650;
  --text: #e8ecf5;
  --muted: #97a3bd;
  --accent: #5b8cff;
  --accent-2: #6ee7c7;
  --danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

.noscript {
  margin: 0;
  padding: 14px 20px;
  text-align: center;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", Meiryo, sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, #1c2742 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(20, 27, 44, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: conic-gradient(from 45deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.15);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 4px;
  background-image: linear-gradient(45deg, #0e1320 25%, transparent 25%),
    linear-gradient(-45deg, #0e1320 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0e1320 75%),
    linear-gradient(-45deg, transparent 75%, #0e1320 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #fff;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}
.brand-text small {
  color: var(--muted);
  font-size: 11px;
}

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

/* ===== Buttons ===== */
.icon-btn,
.primary-btn,
.wide-btn,
.tool,
.bg-btn {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, opacity 0.15s;
}

.icon-btn {
  padding: 8px 12px;
  font-size: 13px;
}
.icon-btn:hover:not(:disabled) {
  background: #2a3550;
  border-color: #3d4868;
}
.icon-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn {
  padding: 9px 18px;
  font-weight: 700;
  font-size: 14px;
  color: #0c1018;
  background: linear-gradient(180deg, var(--accent-2), #46c9a6);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(110, 231, 199, 0.25);
}
.primary-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Layout ===== */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.panel {
  width: 280px;
  flex-shrink: 0;
  padding: 16px;
  overflow-y: auto;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tool-group h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  font-size: 12px;
}
.tool .tool-ico {
  font-size: 20px;
}
.tool:hover {
  background: #2a3550;
}
.tool.active {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.18);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.wide-btn {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent), #4878ef);
  border-color: transparent;
  color: #fff;
}
.wide-btn:hover {
  filter: brightness(1.07);
}
.wide-btn.light {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line);
  font-weight: 500;
  margin-bottom: 8px;
}
.wide-btn.light:hover {
  background: #2a3550;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}
.slider-label output {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ===== ファイル名入力 ===== */
.filename-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filename-base {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 45%;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.text-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input::placeholder {
  color: var(--muted);
}
.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.filename-ext {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.bg-buttons,
.tool-buttons {
  display: grid;
}
.bg-buttons {
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.bg-btn {
  padding: 8px;
  font-size: 13px;
}
.bg-btn.active {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.18);
}

/* ===== Stage ===== */
.stage {
  flex: 1;
  position: relative;
  min-width: 0;
  display: flex;
}

.dropzone {
  margin: auto;
  width: min(620px, 86%);
  border: 2px dashed var(--line);
  border-radius: 18px;
  padding: 54px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.08);
}
.drop-icon {
  font-size: 54px;
}
.drop-title {
  font-size: 20px;
  font-weight: 700;
  margin: 14px 0 6px;
}
.drop-sub {
  color: var(--muted);
  margin: 0;
}
.drop-note {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
}
.dropzone input[type="file"] {
  display: none;
}

/* ===== Canvas ===== */
.canvas-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.canvas-scroll {
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
}
canvas {
  display: block;
  max-width: none;
  box-shadow: var(--shadow);
  image-rendering: auto;
  touch-action: none;
}

/* 透過プレビュー背景 */
.bg-checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #c8ccd4 25%, transparent 25%),
    linear-gradient(-45deg, #c8ccd4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #c8ccd4 75%),
    linear-gradient(-45deg, transparent 75%, #c8ccd4 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
.bg-white {
  background: #ffffff;
}
.bg-black {
  background: #111317;
}

.zoom-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.zoom-bar #zoom-label {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  min-width: 48px;
  text-align: center;
  color: var(--muted);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #0b0f18;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .layout {
    flex-direction: column;
  }
  .panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 14px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
  .tool-group {
    flex: 1 1 140px;
  }
  .brand-text small {
    display: none;
  }
}
