:root {
  --bg: #0d0f14;
  --bg-elev: #151821;
  --bg-elev-2: #1c2030;
  --border: #262b3b;
  --text: #e7e9ef;
  --muted: #8b91a5;
  --accent: #7c6cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 'Leelawadee UI', 'Noto Sans Thai', 'Sukhumvit Set', system-ui, sans-serif;
}

body {
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  overscroll-behavior-y: contain;
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: var(--bg);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 0.8rem;
}

.pill {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
}

.pill.on {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 40%, transparent);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.steps {
  padding-left: 20px;
  color: var(--muted);
  margin: 0 0 16px;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}

textarea.input {
  resize: vertical;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.code {
  text-align: center;
  letter-spacing: 0.3em;
  font-size: 1.3rem;
  text-transform: uppercase;
}

.btn {
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

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

.btn.big {
  min-height: 54px;
  font-size: 1.05rem;
}

.btn.danger {
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.55;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.row {
  display: flex;
  gap: 8px;
}

.row > .btn {
  flex: 1;
}

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

.photo {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--bg-elev-2);
  color: var(--muted);
  overflow: hidden;
  cursor: pointer;
}

.photo img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  grid-area: 1 / 1;
}

.photo span {
  grid-area: 1 / 1;
}

.photo.has-img span {
  align-self: end;
  margin-bottom: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.85rem;
}

.field-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: -6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.chip[aria-pressed='true'] {
  background: color-mix(in srgb, var(--accent) 25%, var(--bg-elev-2));
  border-color: var(--accent);
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

details summary {
  cursor: pointer;
  color: var(--muted);
  padding: 4px 0;
}

details[open] summary {
  margin-bottom: 10px;
}

.error {
  color: var(--danger);
  margin: 8px 0 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

.section-title {
  margin: 4px 0 12px;
}

.jobs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.thumb {
  flex: none;
  width: 56px;
  height: 84px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-elev-2);
}

.job-main {
  flex: 1;
  min-width: 0;
}

.job-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  font-size: 0.85rem;
  color: var(--muted);
}

.status.done {
  color: var(--ok);
}

.status.failed {
  color: var(--danger);
}

.bar {
  height: 6px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  background: var(--bg-elev);
  color: var(--text);
  overflow-y: auto;
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 1rem;
}

.player {
  display: block;
  width: 100%;
  max-height: 60dvh;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  background: #000;
  margin-bottom: 12px;
}

.caption {
  white-space: pre-wrap;
  background: var(--bg-elev-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 12px 0;
}

.note {
  font-size: 0.85rem;
  color: var(--warn);
  margin: 12px 0;
}

.foot {
  margin-top: 28px;
  text-align: center;
}

.link {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #000d;
  color: #fff;
  font-size: 0.9rem;
  z-index: 50;
}

.block {
  display: block;
  width: 100%;
}
