:root {
  --bg: #f2f5fb;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --text: #172033;
  --muted: #5e6b84;
  --accent: #1f7cff;
  --border: #d5deee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #ffffff, var(--bg) 62%);
}

.brand-corner {
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  box-shadow: 0 6px 18px rgba(19, 38, 74, 0.1);
  cursor: pointer;
}

.brand-corner img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.brand-corner span {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #2a3b5f;
}

.brand-corner:hover {
  filter: brightness(1.03);
}

main {
  display: grid;
  grid-template-columns: minmax(340px, 380px) 1fr;
  gap: 14px;
  padding: 54px 14px 88px;
  height: 100vh;
}

.left-panel,
.right-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.left-panel {
  padding: 12px;
  overflow-y: auto;
}

.right-panel {
  display: block;
  padding: 8px;
}

canvas {
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 51, 91, 0.15);
  background: #f5f7fb;
  image-rendering: auto;
}

.preview-tools {
  display: flex;
  justify-content: flex-start;
  align-items: end;
  gap: 12px;
  margin-bottom: 8px;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  height: 100%;
}

.preview-card {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 8px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.preview-card.hidden {
  display: none;
}

.preview-grid.single {
  grid-template-columns: 1fr;
}

.preview-card figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.preview-viewport {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #eef3fb;
  min-height: 0;
  display: grid;
  place-items: start center;
  touch-action: none;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

label,
button,
select,
input[type="text"] {
  font-size: 0.9rem;
}

.btn,
button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: 1px solid #2d6fe5;
  background: linear-gradient(180deg, #2a83ff, #1869df);
  color: white;
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
}

button:hover,
.btn:hover {
  filter: brightness(1.08);
}

select,
input[type="text"] {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
}

#status {
  color: var(--muted);
  margin: 4px 0 12px;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(13, 20, 35, 0.42);
}

.help-modal.hidden {
  display: none;
}

.help-modal-card {
  width: min(560px, 95vw);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 16px 16px 14px;
  box-shadow: 0 18px 40px rgba(13, 20, 35, 0.25);
  position: relative;
}

.help-modal-card h2 {
  margin: 0 0 10px;
}

.help-modal-card p {
  margin: 6px 0;
  line-height: 1.4;
  color: var(--muted);
}

.help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 8px;
  padding: 0;
}

.controls {
  display: grid;
  gap: 10px;
}

.advanced-controls {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  margin-top: 10px;
  padding: 8px;
}

.advanced-controls summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.advanced-controls .controls {
  margin-top: 8px;
}

.control {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--panel-2);
}

.control .top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 5px;
}

.control input[type="range"] {
  width: 100%;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
}

.action-bar button {
  min-width: 64px;
}

@media (max-width: 960px) {
  main {
    grid-template-columns: 1fr;
    height: auto;
  }

  .right-panel {
    order: -1;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .right-panel {
    min-height: 45vh;
  }

  .preview-grid {
    grid-template-columns: 1fr;
  }

  .preview-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .left-panel {
    padding: 10px;
  }

  .btn,
  button,
  select,
  input[type="text"] {
    min-height: 44px;
    font-size: 1rem;
  }

  .control .top {
    font-size: 0.9rem;
  }

  .brand-corner {
    top: 8px;
    left: 8px;
    padding: 5px 8px 5px 5px;
  }

  .brand-corner img {
    width: 24px;
    height: 24px;
  }

  .brand-corner span {
    font-size: 0.72rem;
  }

  .action-bar {
    justify-content: space-between;
  }

  .action-bar button {
    flex: 1;
    min-width: 0;
  }
}
