:root {
  --color-primary: #ce0f69;
  --color-secondary-teal: #009ca6;
  --color-secondary-purple: #68478d;
  --color-tertiary-gold: #ffb81c;
  --color-tertiary-black: #000000;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Several elements below set `display` via a class of equal specificity
   to the UA [hidden] rule, which would otherwise silently win by source
   order and keep them visible while "hidden". Force it explicitly. */
[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: var(--color-tertiary-black);
}

a {
  color: inherit;
}

/* ---------------------------------------------------------------------
   App shell / nav
   --------------------------------------------------------------------- */

.app-shell {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-shell.narrow {
  max-width: 560px;
}

.nav-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
  border-radius: 16px;
  padding: 14px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-brand {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-primary);
  padding: 8px 4px;
}

.nav-brand-link {
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-email {
  font-size: 0.8rem;
  color: #6b7280;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-logout {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #6b7280;
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-logout:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------- */

.card {
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.card.accent {
  border-top: 6px solid transparent;
  border-image: linear-gradient(
    90deg,
    var(--color-primary),
    var(--color-secondary-teal),
    var(--color-secondary-purple),
    var(--color-tertiary-gold)
  );
  border-image-slice: 1;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  margin-bottom: 4px;
  min-width: 0;
}

h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

h2 {
  font-size: 1.1rem;
}

.section-heading {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.subtitle {
  font-size: 0.9rem;
  color: #6b7280;
  line-height: 1.4;
}

.status {
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
  padding: 40px 0;
}

.status.error {
  color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  color: #ffffff;
  background: var(--color-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
  text-decoration: none;
}

.btn-primary:hover {
  box-shadow: 0 0 0 3px rgba(206, 15, 105, 0.12);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
  box-shadow: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--color-tertiary-black);
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease;
  text-decoration: none;
}

.btn-secondary:hover {
  border-color: var(--color-primary);
}

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-secondary.danger:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.btn-text {
  display: inline-block;
  padding: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease;
  text-decoration: none;
}

.btn-text:hover {
  color: var(--color-tertiary-black);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  color: #6b7280;
  background: #f9fafb;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(206, 15, 105, 0.1);
  color: var(--color-primary);
}

.header-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */

.input-group {
  margin-bottom: 20px;
}

.input-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
}

.field-hint {
  font-size: 0.78rem;
  color: #6b7280;
  margin-top: 6px;
  line-height: 1.4;
}

.text-input,
.text-select,
textarea.text-input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--color-tertiary-black);
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus,
.text-select:focus,
textarea.text-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(206, 15, 105, 0.12);
}

.form-error {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

/* ---------------------------------------------------------------------
   Auth gate
   --------------------------------------------------------------------- */

.auth-landing {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  margin: 40px auto;
}

.hero-copy {
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.hero-copy h1 {
  font-size: 1.8rem;
  margin-bottom: 10px;
}

.hero-tagline {
  font-size: 1rem;
  color: #6b7280;
  line-height: 1.5;
  margin-bottom: 22px;
}

.hero-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.hero-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  color: #374151;
  line-height: 1.4;
}

.hero-features li::before {
  content: "✓";
  flex-shrink: 0;
  color: var(--color-secondary-teal);
  font-weight: 700;
}

.auth-shell {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

/* ---------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #6b7280;
}

.empty-state p {
  font-size: 0.9rem;
  margin-top: 6px;
}

/* ---------------------------------------------------------------------
   Gallery (index.html)
   --------------------------------------------------------------------- */

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: #f9fafb;
  border: 1px solid #f0f1f3;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.plan-card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.plan-card-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #e5e7eb;
  overflow: hidden;
}

.plan-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.plan-card-body {
  padding: 12px 14px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.plan-card-name {
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #6b7280;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.plan-card-delete:hover {
  background: #ffffff;
  color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   New plan (upload + crop)
   --------------------------------------------------------------------- */

.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  border: 2px dashed #d1d5db;
  border-radius: 14px;
  text-align: center;
  color: #6b7280;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-drop:hover,
.upload-drop.dragover {
  border-color: var(--color-primary);
  background: rgba(206, 15, 105, 0.03);
}

.upload-drop-icon {
  font-size: 1.8rem;
}

.crop-stage {
  position: relative;
  margin: 0 auto;
  background: #111827;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.crop-stage img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.crop-box {
  position: absolute;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.5);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.crop-handle.nw {
  top: 0;
  left: 0;
  cursor: nwse-resize;
}
.crop-handle.ne {
  top: 0;
  left: 100%;
  cursor: nesw-resize;
}
.crop-handle.sw {
  top: 100%;
  left: 0;
  cursor: nesw-resize;
}
.crop-handle.se {
  top: 100%;
  left: 100%;
  cursor: nwse-resize;
}

/* ---------------------------------------------------------------------
   Editor (plan.html)
   --------------------------------------------------------------------- */

.editor-layout {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

.editor-canvas-card,
.key-card {
  padding: 20px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar .field-hint {
  margin-top: 0;
  flex-basis: 100%;
}

.image-stage {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #e5e7eb;
  touch-action: none;
  user-select: none;
}

.image-stage img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.image-stage.armed {
  cursor: crosshair;
}

.shape-layer {
  position: absolute;
  inset: 0;
}

.shape {
  position: absolute;
  box-sizing: border-box;
  border-width: 2px;
  border-style: solid;
  cursor: move;
}

.shape.box {
  border-radius: 2px;
}

.shape.circle {
  border-radius: 50%;
}

.shape.selected {
  z-index: 5;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--color-tertiary-black);
}

.shape-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 2px solid var(--color-tertiary-black);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
}

.shape-handle.nw {
  top: 0;
  left: 0;
  cursor: nwse-resize;
}
.shape-handle.ne {
  top: 0;
  left: 100%;
  cursor: nesw-resize;
}
.shape-handle.sw {
  top: 100%;
  left: 0;
  cursor: nesw-resize;
}
.shape-handle.se {
  top: 100%;
  left: 100%;
  cursor: nwse-resize;
}

.shape-toolbar {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, calc(-100% - 10px));
}

.shape-toolbar-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.shape-toolbar-swatch.active {
  border-color: var(--color-tertiary-black);
}

.shape-toolbar-divider {
  width: 1px;
  height: 18px;
  background: #e5e7eb;
  flex-shrink: 0;
}

.shape-toolbar-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: #6b7280;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
}

.shape-toolbar-delete:hover {
  background: rgba(206, 15, 105, 0.1);
  color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   Key list (colour legend)
   --------------------------------------------------------------------- */

.key-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.key-entry-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  background: #f9fafb;
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}

.key-entry-row.active {
  border-color: var(--color-primary);
  background: rgba(206, 15, 105, 0.05);
}

.key-swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #d1d5db;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.key-entry-row.active .key-swatch-btn {
  box-shadow: 0 0 0 2px var(--color-primary);
}

.key-swatch-btn::after {
  content: "";
}

.key-label-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  color: inherit;
}

.key-label-input:hover,
.key-label-input:focus {
  border-color: #d1d5db;
  background: #ffffff;
  outline: none;
}

.key-color-input {
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.key-entry-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: #9ca3af;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
}

.key-entry-delete:hover {
  background: rgba(206, 15, 105, 0.1);
  color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   Editable heading (plan name)
   --------------------------------------------------------------------- */

.editable-heading-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  max-width: 100%;
  text-align: left;
}

.editable-heading-btn:hover {
  color: var(--color-primary);
}

.editable-heading-btn .edit-hint {
  font-size: 0.9rem;
  color: #9ca3af;
  font-weight: 400;
}

/* ---------------------------------------------------------------------
   Misc
   --------------------------------------------------------------------- */

.powered-by a {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #6b7280;
  font-size: 0.85rem;
  transition: color 0.15s ease;
}

.powered-by a:hover {
  color: var(--color-tertiary-black);
}

.powered-by-logo {
  width: 20px;
  height: 20px;
  border-radius: 5px;
}

.powered-by strong {
  color: var(--color-primary);
  font-weight: 700;
}

/* ---------------------------------------------------------------------
   Responsive (mobile)
   --------------------------------------------------------------------- */

@media (max-width: 780px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .nav-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .nav-user {
    justify-content: space-between;
  }

  .card {
    padding: 20px;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .card-header .header-actions,
  .card-header > .btn-primary,
  .card-header > .btn-secondary {
    width: 100%;
  }

  .plan-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
