@font-face {
  font-family: "CD81Title";
  src: url("./assets/fonts/avenir-next-condensed-demibold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #15171c;
  --muted: #687180;
  --line: #d7dce4;
  --soft: #f7f8fa;
  --red: #e1172e;
  --blue: #2f73b8;
  --amber: #d28b0d;
  --shadow: 0 18px 40px rgba(20, 28, 38, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 42px;
  padding: 0 18px;
}

button:hover {
  background: #2d323a;
}

button:disabled,
button:disabled:hover {
  background: #d9dee6;
  color: #87909d;
  cursor: not-allowed;
}

.ghost-button {
  background: #eef1f5;
  color: var(--ink);
}

.ghost-button:hover {
  background: #e1e6ee;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.control-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
}

.app-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.app-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--red), var(--amber));
  border: 3px solid #101317;
  border-radius: 8px;
  color: #fff;
  display: flex;
  font-family: "CD81Title", Impact, "Arial Black", sans-serif;
  font-size: 32px;
  height: 56px;
  justify-content: center;
  line-height: 1;
  text-shadow: 2px 2px 0 #101317;
  width: 56px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
  line-height: 1.1;
}

p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.control-section {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.control-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.mobile-tabbar,
.mobile-export-panel {
  display: none;
}

.section-title {
  color: #303742;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.field-label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

textarea {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 118px;
  padding: 12px;
  resize: vertical;
  text-transform: uppercase;
  width: 100%;
}

textarea:focus,
input[type="range"]:focus,
button:focus,
.upload-zone:focus-within {
  outline: 3px solid rgba(47, 115, 184, 0.22);
  outline-offset: 2px;
}

.inline-actions,
.toggle-grid {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 12px;
}

.toggle-grid {
  justify-content: flex-start;
}

.check-control {
  align-items: center;
  color: #303742;
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  min-height: 34px;
}

.check-control input {
  accent-color: var(--red);
  height: 18px;
  width: 18px;
}

.upload-zone {
  align-items: center;
  background: #f7fafc;
  border: 1px dashed #aeb8c6;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  min-height: 64px;
  padding: 12px 14px;
}

.upload-zone.compact {
  min-height: 54px;
}

.upload-zone span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.upload-zone strong {
  font-size: 14px;
  text-align: right;
}

.upload-zone.drag-over {
  background: #fff6f7;
  border-color: var(--red);
}

.range-control {
  align-items: center;
  display: flex;
  font-size: 13px;
  font-weight: 700;
  justify-content: space-between;
  margin: 12px 0 6px;
}

output {
  color: var(--blue);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

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

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.pip-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.pip-empty {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  margin: 0;
  padding: 10px 12px;
}

.pip-item {
  align-items: stretch;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 8px;
}

.pip-item.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 115, 184, 0.13);
}

.pip-item.is-hidden {
  opacity: 0.62;
}

.pip-select-button {
  align-items: flex-start;
  background: transparent;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 42px;
  min-width: 0;
  padding: 0 8px;
  text-align: left;
}

.pip-select-button:hover {
  background: #eef1f5;
}

.pip-select-button span {
  font-size: 13px;
  font-weight: 800;
}

.pip-select-button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pip-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  background: #eef1f5;
  color: var(--ink);
  font-size: 12px;
  min-height: 42px;
  padding: 0 10px;
}

.mini-button:hover {
  background: #e1e6ee;
}

.mini-button.danger {
  background: #fff0f2;
  color: var(--red);
}

.mini-button.danger:hover {
  background: #ffe0e5;
}

.sr-only {
  height: 1px;
  left: -10000px;
  overflow: hidden;
  position: absolute;
  top: auto;
  width: 1px;
}

.preview-panel {
  align-self: start;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: calc(100vh - 36px);
  min-width: 0;
  position: sticky;
  top: 18px;
}

.preview-toolbar {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 14px 16px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.export-actions button:last-child {
  background: var(--blue);
}

.export-actions button:last-child:hover {
  background: #245c94;
}

.mobile-export-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.mobile-status {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  margin: 0 0 12px;
  padding: 10px 12px;
}

.canvas-wrap {
  align-items: center;
  background: #cfd5de;
  border: 1px solid #b8c1ce;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
}

canvas {
  aspect-ratio: 1 / 1;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 10px 28px rgba(19, 25, 34, 0.25);
  cursor: crosshair;
  display: block;
  max-height: calc(100vh - 190px);
  max-width: min(100%, calc(100vh - 190px));
  touch-action: none;
  user-select: none;
  width: 100%;
}

canvas.is-dragging {
  cursor: grabbing;
}

@media (max-width: 980px) {
  .app-shell {
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .control-panel {
    height: auto;
    max-height: none;
    order: 2;
    overflow: visible;
  }

  .preview-panel {
    height: min(100dvh, 860px);
    order: 1;
    position: static;
  }

  canvas {
    max-height: min(55dvh, 560px);
    max-width: min(100%, 55dvh);
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    gap: 10px;
    grid-template-rows: minmax(0, 62dvh) minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 10px;
  }

  .preview-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: auto;
    min-height: 0;
    order: 1;
  }

  .control-panel {
    height: auto;
    min-height: 0;
    order: 2;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 10px;
  }

  .preview-toolbar {
    align-items: center;
    flex-direction: row;
    gap: 8px;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 10px 12px;
  }

  .preview-toolbar h2 {
    font-size: 17px;
  }

  .preview-toolbar p {
    font-size: 12px;
  }

  .preview-toolbar .export-actions {
    flex: 0 0 auto;
    gap: 6px;
  }

  .preview-toolbar .export-actions button {
    font-size: 12px;
    min-height: 36px;
    padding: 0 10px;
  }

  .inline-actions {
    align-items: center;
    flex-direction: row;
  }

  .mobile-tabbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 8px;
    margin: -10px -10px 10px;
    overflow-x: auto;
    padding: 10px;
    position: sticky;
    scrollbar-width: none;
    top: -10px;
    z-index: 3;
  }

  .mobile-tabbar::-webkit-scrollbar {
    display: none;
  }

  .mobile-tabbar button {
    background: #eef1f5;
    color: #303742;
    flex: 0 0 auto;
    font-size: 13px;
    min-height: 36px;
    padding: 0 12px;
  }

  .mobile-tabbar button.is-active {
    background: var(--ink);
    color: #fff;
  }

  .mobile-export-panel {
    display: block;
  }

  .control-section {
    display: none;
  }

  .control-section.is-active {
    display: block;
  }

  .canvas-wrap {
    min-height: 0;
    padding: 10px;
  }

  canvas {
    max-height: calc(62dvh - 102px);
    max-width: min(100%, calc(62dvh - 102px));
  }

  .app-header {
    display: none;
  }

  .section-title {
    margin-bottom: 8px;
  }

  .range-control {
    margin: 10px 0 4px;
  }

  .control-section {
    border-top: 0;
    padding: 0;
  }

  textarea {
    min-height: 88px;
  }

  .upload-zone {
    min-height: 50px;
    padding: 10px 12px;
  }

  .pip-item {
    grid-template-columns: 1fr;
  }

  .pip-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 420px) {
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-toolbar .export-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  canvas {
    max-height: calc(62dvh - 142px);
    max-width: min(100%, calc(62dvh - 142px));
  }
}
