:root {
  color-scheme: light;
  --bg: #f6f4f1;
  --surface: #fffdfa;
  --surface-2: #fdf6f2;
  --ink: #19171a;
  --muted: #6e7179;
  --line: #e2dcd6;
  --soft-line: #f0e9e2;
  --accent: #ce4565;
  --accent-dark: #a92d4c;
  --mint: #157a78;
  --blue: #305c99;
  --gold: #b07a22;
  --danger: #b42348;
  --shadow: 0 18px 42px rgba(44, 37, 31, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(135deg, rgba(206, 69, 101, 0.1), transparent 32%),
    linear-gradient(315deg, rgba(21, 122, 120, 0.1), transparent 38%),
    linear-gradient(180deg, #fffaf5 0%, #f6f4f1 52%, #eff7f6 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.app-header,
.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(169, 45, 76, 0.24);
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.top-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
}

h2 {
  margin-bottom: 8px;
  font-size: 22px;
  line-height: 1.15;
}

p {
  color: var(--muted);
  line-height: 1.7;
}

.ghost-button,
.ghost-link,
.status-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: #4b4f58;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
  padding: 0 14px;
  cursor: pointer;
}

.ghost-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.danger-button {
  border-color: rgba(180, 35, 72, 0.32);
  color: var(--danger);
}

.primary-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-weight: 900;
  padding: 0 20px;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(169, 45, 76, 0.22);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.auth-panel,
.compose-panel,
.result-panel,
.admin-section {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.94);
  box-shadow: var(--shadow);
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.78fr);
  gap: 22px;
  align-items: center;
  padding: 20px;
}

.auth-copy p {
  max-width: 620px;
  margin-bottom: 0;
}

.auth-form,
.compose-form,
.redeem-form,
.card-form,
.settings-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.card-form label,
.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.auth-form input,
.redeem-form input,
.card-form input,
.settings-form input,
.settings-form textarea,
.row-controls input,
.card-output {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.auth-form input:focus,
.redeem-form input:focus,
.card-form input:focus,
.settings-form input:focus,
.settings-form textarea:focus,
.row-controls input:focus,
.card-output:focus {
  border-color: rgba(206, 69, 101, 0.55);
  box-shadow: 0 0 0 3px rgba(206, 69, 101, 0.1);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #f8f1ec;
}

.auth-tab {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.auth-tab.is-active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 8px 18px rgba(169, 45, 76, 0.1);
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--mint);
  font-size: 13px;
  font-weight: 800;
}

.form-message.is-error {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.94fr) minmax(360px, 1.06fr);
  gap: 18px;
  align-items: start;
}

.compose-panel,
.result-panel,
.admin-section {
  padding: 16px;
}

.usage-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.usage-card article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.usage-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.usage-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.redeem-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.step-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.step-title > span {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff0f3;
  color: var(--accent-dark);
  font-weight: 900;
}

.step-title h2 {
  margin: 0 0 4px;
}

.step-title p {
  margin: 0;
  font-size: 14px;
}

.upload-grid,
.preview-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.upload-tile {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(48, 92, 153, 0.08), transparent 55%), #fff;
  padding: 14px;
  cursor: pointer;
}

.upload-tile.accent {
  background: linear-gradient(135deg, rgba(206, 69, 101, 0.1), transparent 58%), #fff;
}

.upload-tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-kind {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.upload-tile strong {
  font-size: 19px;
}

.pick-button {
  width: fit-content;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  background: #f6f0ea;
  color: #4d4540;
  font-size: 13px;
  font-weight: 900;
  padding: 0 12px;
}

.preview-card {
  position: relative;
  min-height: 176px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(21, 122, 120, 0.08), transparent),
    #fbf7f3;
}

.preview-card img {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.preview-card img:not([hidden]) + .preview-empty {
  display: none;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
}

.action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  cursor: default;
}

.status-pill.is-working {
  border-color: rgba(206, 69, 101, 0.28);
  background: #fff0f3;
  color: var(--accent-dark);
}

.status-pill.is-success {
  border-color: rgba(21, 122, 120, 0.24);
  background: #ecf8f7;
  color: var(--mint);
}

.status-pill.is-error {
  border-color: rgba(180, 35, 72, 0.28);
  background: #fff0f3;
  color: var(--danger);
}

.result-panel {
  position: sticky;
  top: 18px;
}

.records-panel {
  margin-top: 16px;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
}

.section-title.compact {
  align-items: center;
}

.result-frame {
  min-height: 590px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(206, 69, 101, 0.08), transparent 45%),
    linear-gradient(315deg, rgba(21, 122, 120, 0.08), transparent 48%),
    #fffaf7;
}

.result-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 76vh;
  object-fit: contain;
}

.result-empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.result-mark {
  width: 52px;
  height: 52px;
  display: block;
  border: 2px solid rgba(176, 122, 34, 0.35);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 45%, rgba(176, 122, 34, 0.18) 45% 55%, transparent 55%),
    #fff;
}

.admin-app {
  display: grid;
  gap: 16px;
}

.admin-toolbar h1 {
  margin-bottom: 0;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.82);
  padding: 6px;
  box-shadow: 0 12px 30px rgba(44, 37, 31, 0.06);
}

.admin-tab {
  min-height: 42px;
  flex: 1 1 150px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.admin-tab.is-active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 8px 18px rgba(169, 45, 76, 0.1);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-card,
.table-row,
.empty-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.summary-card {
  padding: 14px;
}

.summary-card span,
.table-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.admin-section {
  margin-bottom: 16px;
}

.section-note {
  margin: 6px 0 0;
  font-size: 13px;
}

.settings-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-form label small {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mode-choice {
  min-height: 44px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-choice label,
.gift-switch {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #4b4f58;
  padding: 0 12px;
}

.mode-choice input,
.gift-choice input[type="checkbox"] {
  width: auto;
  min-height: auto;
  padding: 0;
}

.gift-choice {
  min-height: 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 136px;
  gap: 8px;
}

.gift-choice > input {
  min-height: 44px;
}

.settings-prompt,
.settings-actions {
  grid-column: 1 / -1;
}

.settings-form textarea {
  min-height: 280px;
  padding: 12px;
  line-height: 1.55;
  resize: vertical;
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-form {
  grid-template-columns: 140px 140px auto;
  align-items: end;
}

.card-output {
  min-height: 116px;
  margin-top: 12px;
  padding: 12px;
  line-height: 1.7;
  resize: vertical;
}

.table-list {
  display: grid;
  gap: 10px;
}

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

.row-main {
  min-width: 0;
}

.row-main strong {
  display: block;
  overflow-wrap: anywhere;
}

.row-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.inline-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.inline-field input {
  width: 112px;
}

.password-field input {
  width: 154px;
}

.switch-line {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.empty-list {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  font-weight: 800;
}

.records-list {
  display: grid;
  gap: 10px;
}

.record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.record-row > div {
  min-width: 0;
}

.record-row strong,
.record-row small {
  display: block;
}

.record-row strong {
  font-size: 13px;
}

.record-row small {
  max-width: 360px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 23, 26, 0.36);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  width: min(420px, 100%);
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(25, 23, 26, 0.2);
  padding: 16px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

@media (max-width: 1080px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .workspace,
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
  }

  .result-frame {
    min-height: 420px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .app-header,
  .admin-toolbar {
    align-items: flex-start;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand strong {
    font-size: 18px;
  }

  .brand small {
    max-width: 190px;
    white-space: normal;
    line-height: 1.35;
  }

  .top-actions,
  .toolbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ghost-button,
  .ghost-link,
  .status-pill {
    min-height: 36px;
    padding: 0 10px;
  }

  .auth-panel,
  .compose-panel,
  .result-panel,
  .admin-section {
    padding: 12px;
  }

  h1 {
    font-size: 30px;
  }

  .usage-card,
  .upload-grid,
  .preview-strip,
  .redeem-form,
  .card-form,
  .gift-choice,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .settings-prompt,
  .settings-actions {
    grid-column: auto;
  }

  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .upload-tile {
    min-height: 112px;
  }

  .preview-card {
    min-height: 210px;
  }

  .action-bar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 -12px -12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--soft-line);
    background: rgba(255, 253, 250, 0.95);
    backdrop-filter: blur(14px);
  }

  .action-bar .primary-button {
    flex: 1;
  }

  .status-pill {
    max-width: 136px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .result-frame {
    min-height: 360px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-row small {
    max-width: 100%;
  }

  .row-controls {
    width: 100%;
    justify-content: flex-start;
  }
}

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

  .brand small {
    display: none;
  }

  .usage-card strong {
    font-size: 24px;
  }

  .action-bar {
    gap: 8px;
  }

  .status-pill {
    max-width: 112px;
  }

  .summary-card strong {
    font-size: 21px;
  }
}
