:root {
  color-scheme: dark;
  --bg: #0c1218;
  --surface: #131c24;
  --surface-2: #19242e;
  --border: #283847;
  --border-strong: #3c5368;
  --text: #e4ecf2;
  --muted: #8ea3b5;
  --accent: #4ec28c;
  --accent-hover: #62d49e;
  --primary: #4ea1e0;
  --primary-hover: #68b4ee;
  --danger: #df5b5b;
  --paper: #f5f0e1;
  --ink: #141e3c;
  --radius: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top right, #142230 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: rgba(255, 255, 255, 0.07);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.88em;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(12, 18, 24, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, #9a2f2f, #5c1919);
  border: 1px solid rgba(255, 190, 190, 0.3);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff3e0;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
}

.brand-sub {
  color: var(--primary);
  font-weight: 500;
}

.tagline {
  margin: 0.15rem 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

/* Main Workspace */
.workspace {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.editor-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-sticky {
  position: sticky;
  top: 5.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.card-header h2,
.howto-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.pill {
  font-size: 0.74rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(78, 194, 140, 0.14);
  color: #8ee5bc;
  border: 1px solid rgba(78, 194, 140, 0.35);
  white-space: nowrap;
}

.pill-muted {
  background: rgba(142, 163, 181, 0.12);
  color: var(--muted);
  border-color: var(--border);
}

/* Form Elements */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.span-2 {
  grid-column: span 2;
}

@media (max-width: 600px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field > span {
  font-size: 0.84rem;
  color: #c7d6e2;
  font-weight: 500;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.92rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
.dropzone:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.hint {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.sub-details {
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.02);
}

.sub-details summary {
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--muted);
  user-select: none;
}

.sub-details-body {
  margin-top: 0.7rem;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(78, 161, 224, 0.08);
}

.dropzone-prompt {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.dropzone-prompt small {
  color: var(--muted);
  font-size: 0.78rem;
}

.link-like {
  color: var(--primary);
  text-decoration: underline;
}

.dropzone-loaded {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.dropzone-loaded img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  background: repeating-conic-gradient(#24313d 0% 25%, #1a242e 0% 50%) 50% / 12px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 4px;
}

.dropzone-meta {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.dropzone-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.dropzone-meta span {
  font-size: 0.8rem;
  color: var(--muted);
}

/* PNG Resize & Aspect Ratio Box */
.resize-box {
  margin-top: 0.55rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.resize-box[hidden] {
  display: none;
}

.resize-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #c7d6e2;
}

.resize-dims-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.field-inline input[type="number"] {
  width: 82px;
  padding: 0.35rem 0.5rem;
  font-size: 0.84rem;
}

.dims-x {
  color: var(--muted);
  font-weight: 600;
}

.lock-ratio-label {
  font-size: 0.8rem;
  color: #c7d6e2;
  margin-left: 0.25rem;
}

.resize-presets-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 0.76rem;
  color: var(--muted);
  margin-right: 0.1rem;
}

.preset-sep {
  margin-left: 0.45rem;
}

.preset-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.24rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.preset-btn:hover {
  border-color: var(--primary);
  background: rgba(78, 161, 224, 0.14);
}

.fit-select {
  padding: 0.28rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}

.fit-select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.compact-field {
  margin-bottom: 0;
}

.compact-field > span {
  font-size: 0.78rem;
}

/* Segmented Radio */
.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.seg-option {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.seg-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(78, 161, 224, 0.12);
}

.seg-option input {
  margin-top: 0.2rem;
  accent-color: var(--primary);
}

.seg-option span {
  display: flex;
  flex-direction: column;
}

.seg-option strong {
  font-size: 0.88rem;
}

.seg-option small {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Handle Grid */
.handle-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.55rem;
}

@media (max-width: 600px) {
  .handle-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.handle-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.76rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.handle-card:hover {
  border-color: var(--border-strong);
}

.handle-card.selected {
  border-color: var(--accent);
  background: rgba(78, 194, 140, 0.14);
}

.handle-card img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.handle-upload-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px dashed var(--border-strong);
  font-size: 1.3rem;
  color: var(--muted);
}

/* Merchant Box */
.merchant-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.85rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.88rem;
}

.checkbox-row small {
  color: var(--muted);
}

.merchant-controls {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.merchant-controls[hidden] {
  display: none;
}

.inline-pair {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.inline-pair span {
  font-size: 0.82rem;
  color: var(--muted);
}

.store-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.chip:has(input:checked) {
  border-color: var(--primary);
  background: rgba(78, 161, 224, 0.14);
}

/* Craft Ingredients */
.ingredients-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

.ingredient-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px auto;
  gap: 0.45rem;
  align-items: center;
}

.ingredient-row input {
  padding: 0.45rem 0.6rem;
  font-size: 0.86rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.58rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #07131d;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #061b12;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.btn-danger {
  background: rgba(223, 91, 91, 0.16);
  border-color: rgba(223, 91, 91, 0.45);
  color: #ff9c9c;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(223, 91, 91, 0.28);
}

.btn-sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.8rem;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.status-msg {
  min-height: 1.2rem;
  font-size: 0.84rem;
  margin-bottom: 0.55rem;
}

.status-msg.error {
  color: #ff8e8e;
}

.status-msg.ok {
  color: #84e5b7;
}

/* Pack List */
.pack-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.empty-state {
  margin: 0;
  padding: 0.85rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.pack-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pack-item.editing {
  border-color: var(--primary);
  background: rgba(78, 161, 224, 0.1);
}

.pack-item-thumbs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.pack-item-thumbs img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  padding: 3px;
}

.pack-item-info {
  flex: 1;
  min-width: 0;
}

.pack-item-info strong {
  display: block;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pack-item-info small {
  color: var(--muted);
  font-size: 0.76rem;
}

.pack-item-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Live Paper Preview */
.paper-stage {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0 0.85rem;
}

.paper-sheet {
  position: relative;
  width: 100%;
  max-width: 330px;
  aspect-ratio: 35 / 54;
  background: var(--paper);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  user-select: none;
  padding: 4% 6%;
  display: flex;
  flex-direction: column;
}

.paper-title {
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  color: #141e3c;
}

.paper-divider {
  height: 1px;
  background: rgba(140, 130, 110, 0.55);
  margin: 0.35rem 0 0.55rem;
}

.paper-body {
  font-size: 0.72rem;
  line-height: 1.45;
  color: #17233b;
}

.paper-body p {
  margin: 0 0 0.3rem;
}

.paper-filler {
  margin-top: 0.45rem !important;
  opacity: 0.85;
}

.paper-sigs {
  margin-top: auto;
  margin-bottom: 14%;
  font-size: 0.72rem;
}

.paper-sigs-label {
  color: #5a5f69;
  font-weight: 700;
  font-size: 0.65rem;
}

.paper-sig-line {
  color: #19378c;
  font-weight: 600;
}

.stamp-overlay {
  position: absolute;
  cursor: grab;
  border: 1px dashed rgba(78, 161, 224, 0.55);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.stamp-overlay:active {
  cursor: grabbing;
  border-color: var(--primary);
}

.stamp-overlay img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.88;
  pointer-events: none;
}

.paper-btns {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 2.5%;
}

.paper-btn-mock {
  background: #232a2c;
  color: #ff6e6e;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem;
  border: 1px solid #3c474a;
}

/* Inventory Tooltip Preview */
.inv-preview {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.75rem;
  background: #0d141a;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.inv-slot {
  width: 60px;
  height: 60px;
  background: #1a242c;
  border: 1px solid #415566;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 6px;
}

.inv-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.inv-tooltip {
  min-width: 0;
  flex: 1;
}

.inv-name {
  font-weight: 700;
  font-size: 0.94rem;
}

.inv-mod-tag {
  font-size: 0.76rem;
  color: #7ab8e8;
  margin-bottom: 0.25rem;
}

.inv-desc {
  font-size: 0.82rem;
  color: #c5d2dc;
}

.inv-price {
  margin-top: 0.35rem;
  font-size: 0.76rem;
  color: #d9c273;
}

/* XML Preview */
.xml-preview-card summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}

.xml-tabs {
  display: flex;
  gap: 0.4rem;
  margin: 0.8rem 0 0.5rem;
  flex-wrap: wrap;
}

.xml-tab {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.xml-tab.active {
  background: rgba(78, 161, 224, 0.16);
  border-color: var(--primary);
  color: var(--text);
}

.xml-code {
  margin: 0;
  padding: 0.75rem;
  background: #0a0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.76rem;
  overflow-x: auto;
  max-height: 300px;
  color: #cde0ef;
}

/* How-To */
.howto-card ol {
  margin: 0.55rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.84rem;
  color: #c4d3df;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
