:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-alt: #eaf1ed;
  --ink: #222725;
  --muted: #66736d;
  --line: #d3ded8;
  --primary: #16697a;
  --primary-dark: #0f4f5c;
  --accent: #f4b942;
  --danger: #b84d45;
  --shadow: 0 18px 46px rgb(34 39 37 / 0.1);
  --radius: 8px;
  --tap: 48px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, rgb(22 105 122 / 0.1), transparent 260px), var(--bg);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sprite,
input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  width: min(1180px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    14px
    max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.page-count {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.page-count {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.84);
}

.page-count.is-hidden {
  display: none;
}

.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.export-bar {
  display: grid;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  gap: 8px;
  border-radius: 7px;
  font-weight: 900;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: var(--tap);
  padding: 0;
}

.primary-icon {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.icon-button.danger {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
}

.editor-panel {
  position: relative;
  display: grid;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111816;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#editor-canvas,
.empty-state {
  grid-area: 1 / 1;
}

#editor-canvas {
  width: 100%;
  height: 100%;
  min-height: 520px;
  touch-action: none;
}

.empty-state {
  display: grid;
  place-content: center;
  gap: 10px;
  color: rgb(255 255 255 / 0.72);
  font-weight: 900;
  text-align: center;
}

.empty-state svg {
  width: 56px;
  height: 56px;
  justify-self: center;
}

.empty-state.is-hidden {
  display: none;
}

.editor-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.thumb-row {
  display: flex;
  gap: 7px;
  min-height: 54px;
  overflow-x: auto;
  padding: 2px 0 4px;
}

.thumb-button {
  position: relative;
  flex: 0 0 46px;
  height: 54px;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 8px 18px rgb(34 39 37 / 0.08);
}

.thumb-button.is-active {
  border-color: var(--accent);
}

.thumb-button img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  object-fit: cover;
  background: var(--surface-alt);
}

.thumb-button span {
  position: absolute;
  right: 2px;
  bottom: 2px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 18px;
}

.export-bar {
  grid-template-columns: minmax(0, 1fr) var(--tap) var(--tap);
}

.format-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  min-height: var(--tap);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-alt);
}

.format-control button {
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.format-control button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 14px rgb(34 39 37 / 0.1);
}

@media (min-width: 860px) {
  .app {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 58px;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .editor-actions {
    flex-direction: column;
    justify-content: start;
  }

  .thumb-row {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 1.5rem;
  }

  .editor-panel,
  #editor-canvas {
    min-height: 580px;
  }

  .export-bar {
    grid-template-columns: minmax(0, 1fr) var(--tap) var(--tap);
  }
}
