:root {
  color-scheme: light;
  --bg: #fff5e8;
  --panel: #fffaf3;
  --panel-strong: #ffead3;
  --ink: #231815;
  --muted: #7a6257;
  --line: #e5c7ad;
  --accent: #ff935b;
  --accent-dark: #c95823;
  --blue: #5b8ee8;
  --purple: #b184d9;
  --shadow: rgba(91, 59, 32, 0.17);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 240px),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
}

.app-top,
.quick-settings,
.action-bar {
  display: grid;
  gap: 8px;
  align-items: center;
}

.app-top {
  grid-template-columns: minmax(76px, 1fr) auto minmax(76px, 1fr);
}

.quick-settings {
  grid-template-columns: 1fr 0.65fr 1.2fr;
  margin: 10px 0;
}

.action-bar {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  grid-template-columns: 1fr 1.1fr 1fr;
  margin-top: 12px;
  padding-top: 8px;
  background: linear-gradient(180deg, transparent, var(--bg) 38%);
}

.back,
.app-top button,
.quick-settings button,
.action-bar button,
.selector-row button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(180deg, #fffdf9, #ffe8d0);
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.back:hover,
.app-top button:hover,
.quick-settings button:hover,
.action-bar button:hover,
.selector-row button:hover {
  border-color: var(--accent-dark);
  box-shadow: 0 6px 18px rgba(91, 59, 32, 0.22);
  transform: translateY(-1px);
}

.back:active,
.app-top button:active,
.quick-settings button:active,
.action-bar button:active,
.selector-row button:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 8px rgba(91, 59, 32, 0.18);
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6dfc7;
  box-shadow: 0 5px 16px var(--shadow);
}

.mode-toggle button {
  min-width: 76px;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.mode-toggle .active {
  background: linear-gradient(180deg, #76aaff, #5c8ee8);
  color: #101721;
}

.preview-area {
  position: relative;
  display: grid;
  justify-items: center;
  margin: 10px 0;
}

canvas {
  display: block;
  width: auto;
  max-width: min(100%, 330px);
  height: min(49dvh, 520px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(88, 55, 29, 0.16);
}

.engine-status {
  width: min(100%, 330px);
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 250, 243, 0.92);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
  box-shadow: 0 5px 16px rgba(91, 59, 32, 0.09);
}

.quick-settings button {
  background: linear-gradient(180deg, #fffaf6, #ffe3c2);
}

.quick-settings .unlocked {
  background: linear-gradient(180deg, #f0e2ff, #d8bbff);
  border-color: #b184d9;
}

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

.selector-row {
  display: grid;
  grid-template-columns: 36px 40px minmax(0, 1fr) 40px 38px 34px 48px;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

body:not(.full-mode) .selector-row {
  grid-template-columns: 36px 42px minmax(0, 1fr) 42px 38px;
}

body:not(.full-mode) .reset,
body:not(.full-mode) .count {
  display: none;
}

.selector-row.locked {
  opacity: 0.58;
}

.selector-row.locked .value {
  background: #ddd4cb;
}

.selector-row .icon {
  display: block;
  width: 36px;
  height: 36px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff1df;
  object-fit: contain;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.selector-row .value {
  min-width: 0;
  height: 40px;
  padding: 5px 9px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.selector-row .value strong,
.selector-row .value span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selector-row .value strong {
  color: var(--muted);
  font-size: 9px;
  line-height: 11px;
  text-transform: uppercase;
}

.selector-row .value span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  line-height: 18px;
}

.nav-button {
  position: relative;
  min-width: 40px;
  padding: 0;
  background: linear-gradient(180deg, #fff5ec, #ffc694);
}

.nav-button::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border-top: 3px solid #201714;
  border-right: 3px solid #201714;
  content: "";
}

.nav-button.prev::before {
  transform: translate(-35%, -50%) rotate(-135deg);
}

.nav-button.next::before {
  transform: translate(-65%, -50%) rotate(45deg);
}

.random {
  min-width: 38px;
  padding: 0;
  background: linear-gradient(180deg, #f5eaff, #d7b5f4);
  border-color: #c39be4;
  font-size: 18px;
}

.reset {
  min-width: 34px;
  padding: 0;
  background: linear-gradient(180deg, #fffaf7, #ead9c6);
}

.count {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.action-bar button {
  min-height: 46px;
  background: linear-gradient(180deg, #ffe9d8, #ffc494);
}

#renderLocal {
  background: linear-gradient(180deg, #ffae78, var(--accent));
  border-color: var(--accent-dark);
}

#saveImage {
  background: linear-gradient(180deg, #e8f2ff, #9fc2ff);
  border-color: #6b98de;
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 7px;
    padding-right: 7px;
  }

  .selector-row {
    grid-template-columns: 32px 36px minmax(0, 1fr) 36px 34px 30px 42px;
    gap: 5px;
  }

  .selector-row .icon {
    width: 32px;
    height: 34px;
  }

  .selector-row .value {
    height: 38px;
    padding-left: 7px;
    padding-right: 7px;
  }

  .selector-row .value span {
    font-size: 12px;
  }

  .count {
    font-size: 10px;
  }

  body:not(.full-mode) .selector-row {
    grid-template-columns: 32px 38px minmax(0, 1fr) 38px 34px;
  }

  canvas {
    height: min(46dvh, 470px);
  }
}

@media (max-width: 350px) {
  .selector-row {
    grid-template-columns: 30px 34px minmax(0, 1fr) 34px 32px;
  }

  .reset,
  .count {
    display: none;
  }

  .app-top {
    grid-template-columns: 1fr;
  }
}
