:root {
  --ink: #29382d;
  --muted: #68776a;
  --paper: #fffdf8;
  --paper-soft: #f7fbf4;
  --green: #426d55;
  --green-dark: #294736;
  --mint: #a7dab8;
  --peach: #e8a38a;
  --peach-dark: #b96f58;
  --gold: #d5b45e;
  --line: rgba(76, 111, 85, 0.2);
  --shadow: 0 14px 36px rgba(54, 78, 59, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 4%, rgba(248, 222, 218, .75), transparent 25rem),
    radial-gradient(circle at 92% 8%, rgba(244, 223, 158, .48), transparent 22rem),
    linear-gradient(180deg, #fbfff8 0%, #edf5ed 44%, #e3efe5 100%);
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .54; }
textarea { resize: vertical; }

.app-shell {
  width: min(1560px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px clamp(14px, 2.4vw, 38px) 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 0 22px;
  border-bottom: 1px solid var(--line);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; }
h1 { margin-bottom: 7px; font-size: clamp(30px, 3.5vw, 46px); letter-spacing: .04em; }
h1::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 12px;
  border-radius: 50%;
  background: #f8deda;
  box-shadow: 14px 0 0 #96d5ad, 28px 0 0 #f4df9e;
  vertical-align: middle;
}
h2 { margin-bottom: 0; font-size: 28px; }
h3 { margin: 0; font-size: 19px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .18em;
}

.subtext { margin-bottom: 0; color: var(--muted); font-size: 16px; }

.status-pill, .demo-badge {
  max-width: 440px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, .84);
  color: var(--muted);
  font-size: 15px;
}
.status-pill.is-success { background: #e1f1e5; color: #28503c; }
.status-pill.is-warning, .demo-badge { background: #fff2ce; color: #765619; }
.status-pill.is-error { background: #fbe5e1; color: #913c3c; }

.primary-button, .secondary-button, .ghost-button, .copy-button, .item-card button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 800;
}

.primary-button {
  border-color: var(--green-dark);
  background: var(--green);
  color: white;
  box-shadow: 0 3px 0 var(--green-dark);
}
.primary-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--green-dark); }
.secondary-button {
  border-color: #c87b62;
  background: linear-gradient(#f3baa4, var(--peach));
  color: #3a2c27;
  box-shadow: 0 3px 0 #c87b62;
}
.ghost-button { border-color: var(--line); background: var(--paper); color: var(--ink); }
.large-button { min-height: 48px; margin-top: 16px; }

.lookup-panel {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(340px, 1.2fr);
  align-items: end;
  gap: 18px 28px;
  margin: 22px 0 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 248, .88);
  box-shadow: var(--shadow);
}
.lookup-panel p:not(.eyebrow) { margin: 8px 0 0; color: var(--muted); }
.lookup-form { display: grid; gap: 7px; }
.lookup-form label { font-size: 14px; font-weight: 800; }
.lookup-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.lookup-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--ink);
}
.lookup-row input:focus, .search-input:focus, textarea:focus {
  border-color: var(--green);
  outline: 3px solid rgba(66, 109, 85, .16);
}
.lookup-results {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
.lookup-result {
  display: grid;
  gap: 2px;
  min-height: 58px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}
.lookup-result:hover, .lookup-result:focus-visible { border-color: var(--green); background: #edf6ed; }
.lookup-result span { color: var(--muted); font-size: 14px; }
.lookup-empty { grid-column: 1 / -1; margin: 0; padding: 10px; text-align: center; }
.privacy-note { grid-column: 1 / -1; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }

.summary-strip {
  display: grid;
  grid-template-columns: 1.15fr repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--line);
}
.summary-strip > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  background: rgba(255,253,248,.94);
}
.summary-strip span, .save-state { color: var(--muted); font-size: 15px; }
.summary-strip strong { font-size: 18px; white-space: nowrap; }

.subscriber-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 14px;
  padding: 14px 17px;
  border: 1px solid rgba(214, 174, 88, .45);
  border-radius: 13px;
  background: #fff4d8;
}
.subscriber-notice p { margin: 4px 0 0; color: #755a29; font-size: 16px; }
.subscriber-notice > span {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.7);
  color: #755a29;
  font-size: 15px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(720px, 1fr) 340px;
  align-items: start;
  gap: 18px;
  margin-top: 18px;
}

.preview-panel, .command-panel, .collection-panel {
  min-width: 0;
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,253,248,.93);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(280px, .82fr) minmax(420px, 1.18fr);
  align-items: start;
  gap: 14px;
}

.standing-preview, .bar-preview {
  position: relative;
  min-height: 470px;
  overflow: hidden;
  border: 1px solid rgba(76, 111, 85, .18);
  border-radius: 13px;
}

.standing-preview {
  background:
    linear-gradient(rgba(255,255,255,.58), rgba(210,231,213,.3)),
    radial-gradient(circle at 18% 16%, rgba(248,222,218,.58) 0 11px, transparent 12px),
    radial-gradient(circle at 80% 22%, rgba(150,213,173,.3) 0 9px, transparent 10px),
    repeating-linear-gradient(90deg, rgba(129,172,143,.08) 0 1px, transparent 1px 30px),
    #f3faf0;
}

.preview-label {
  position: absolute;
  z-index: 10;
  top: 12px;
  left: 12px;
  padding: 5px 9px;
  border: 1px solid rgba(231,169,143,.34);
  border-radius: 999px;
  background: rgba(255,253,248,.9);
  color: #3d694d;
  font-size: 15px;
  font-weight: 900;
}

.standing-stage, .counter-character-stage, .counter-drink-stage {
  position: absolute;
  z-index: 3;
  left: 50%;
  aspect-ratio: 200 / 350;
  transform: translateX(-50%);
  filter: drop-shadow(0 12px 15px rgba(34,50,38,.22));
}
.standing-stage {
  bottom: clamp(8px, 1vw, 12px);
  width: min(265px, 70%);
}

.bar-preview {
  --bar-scene-x: 58%;
  min-height: 0;
  aspect-ratio: 611 / 773;
  background:
    linear-gradient(180deg, rgba(16,24,20,.05), rgba(16,24,20,.26)),
    url("./images/bar-background.png") var(--bar-scene-x) top / auto 100% no-repeat,
    #e9f2e5;
}
.lamp-glow {
  position: absolute;
  z-index: 1;
  top: -30%;
  left: 50%;
  width: 72%;
  height: 90%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(255,231,166,.42), transparent 65%);
}
.counter-character-stage, .counter-drink-stage {
  width: 40%;
}
.counter-character-stage {
  z-index: 3;
  bottom: 18%;
}
.counter-drink-stage {
  z-index: 6;
  bottom: 14%;
  pointer-events: none;
}
.counter-front {
  position: absolute;
  z-index: 5;
  right: 0;
  bottom: 0;
  left: 0;
  height: 36.78%; /* 523 / 1422: keep the counter at the background image's scale */
  background: url("./images/bar-counter.png") var(--bar-scene-x) top / auto 100% no-repeat;
  filter: brightness(.9);
}

.character-layer, .accessory-layers img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

#standingDrink {
  transform: translateX(-18%);
}

.random-costume-notice {
  position: absolute;
  z-index: 4;
  top: 48%;
  left: 50%;
  width: min(230px, 90%);
  margin: 0;
  padding: 10px 12px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255,232,174,.72);
  border-radius: 9px;
  background: rgba(28,34,31,.86);
  color: #fff5d8;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
}

.nameplate-preview {
  position: absolute;
  z-index: 7;
  top: 20%;
  left: 50%;
  display: grid;
  width: min(254px, 40%);
  aspect-ratio: 254 / 70;
  place-items: center;
  transform: translateX(-50%);
  background: transparent center / 100% 100% no-repeat;
  filter: drop-shadow(0 6px 8px rgba(30,21,15,.24));
}
.nameplate-preview span {
  max-width: 78%;
  overflow: hidden;
  color: var(--nameplate-text, #3b2b1f);
  font-size: clamp(19px, 1.7vw, 25px);
  font-weight: 900;
  letter-spacing: .03em;
  line-height: 1;
  text-shadow: var(--nameplate-shadow, 0 1px 0 rgba(255,255,255,.55));
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 1px;
  overflow: hidden;
  margin-top: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--line);
}
.selection-row {
  display: grid;
  grid-template-columns: 98px minmax(0,1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 43px;
  padding: 7px 11px;
  background: var(--paper);
}
.selection-row span { color: var(--muted); font-size: 14px; }
.selection-row strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.text-button { border: 0; background: transparent; color: var(--green); font-size: 14px; font-weight: 800; }

.save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 13px;
}
.save-row p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.save-row button { flex: 0 0 auto; }

.command-panel { display: grid; gap: 14px; }
.command-section {
  display: grid;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.75), rgba(243,250,240,.82));
}
.command-section p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.command-section code { color: #7c4937; font-weight: 900; }
.command-section textarea, .exchange-warning textarea {
  width: 100%;
  min-height: 92px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfff9;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
.copy-button {
  justify-self: stretch;
  border-color: #9fc9aa;
  background: #eaf6eb;
  color: #245943;
}
.exchange-target {
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #fff4d8;
  color: #71531f;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.5;
}
.command-message { min-height: 18px; color: var(--green); font-size: 14px; line-height: 1.5; }
.exchange-warning {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(185, 111, 88, .48);
  border-radius: 12px;
  background: #fff7ed;
}
.exchange-warning[hidden] { display: none; }
.exchange-warning p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.missing-item-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.missing-item-list li, .point-breakdown > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 7px;
  background: rgba(255,255,255,.72);
  font-size: 14px;
}
.point-breakdown { display: grid; gap: 4px; margin: 0; }
.point-breakdown dt { color: var(--muted); }
.point-breakdown dd { margin: 0; font-weight: 900; }
.exchange-unavailable-message { min-height: 20px; }
.apply-warning {
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(185, 111, 88, .38);
  border-radius: 10px;
  background: #fff0e9;
  color: #704231;
  font-size: 14px;
}
.apply-warning strong { display: block; margin-bottom: 5px; }

.collection-panel { margin-top: 18px; }
.collection-heading { margin-bottom: 12px; }
.owned-toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 15px; font-weight: 700; }
.owned-toggle input { accent-color: var(--green); }
.filter-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 220px;
  gap: 10px;
  margin-bottom: 13px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e4f0e5;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}
.tab.is-active { border-color: #73ad88; background: linear-gradient(#b9e5c7, #96d5ad); color: #244530; }
.search-input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}
.item-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 5px 15px rgba(72,103,75,.06);
}
.item-card.is-selected { border-color: var(--peach); outline: 2px solid rgba(232,163,138,.72); outline-offset: 1px; }
.item-card.is-unavailable { border-color: rgba(184, 143, 54, .45); background: #fffbef; }
.item-card.is-unavailable .item-image-wrap { filter: saturate(.55); opacity: .78; }
.item-image-wrap {
  position: relative;
  display: grid;
  height: 154px;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 18%, rgba(248,222,218,.42), transparent 30%),
    linear-gradient(180deg, rgba(255,255,255,.76), rgba(228,240,229,.46));
}
.item-image-wrap img {
  position: absolute;
  inset: 5%;
  display: block;
  width: 90%;
  height: 90%;
  object-fit: contain;
  image-rendering: pixelated;
}
.item-image-wrap img.is-thumbnail-processing {
  opacity: 0;
}
.item-card[data-type="nameplate"] .item-image-wrap img {
  inset: 12% 3%;
  width: 94%;
  height: 76%;
}
.rarity, .lock-badge, .slot-badge {
  position: absolute;
  top: 7px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}
.rarity { right: 7px; background: rgba(255,253,248,.9); color: #453725; border: 1px solid var(--line); }
.rarity-3 { background: #c9e3ff; color: #123b66; }
.rarity-4 { background: #e1ccff; color: #452272; }
.rarity-5 { background: #f8dfa0; color: #614400; }
.rarity-6 {
  background: linear-gradient(120deg, #ffd0d0, #ffe9a6, #c9f0d6, #c9e3ff, #e1ccff);
  color: #4a2c00;
}
.lock-badge { left: 7px; background: #fff1c5; color: #7a571c; }
.slot-badge { left: 7px; top: auto; bottom: 7px; background: rgba(41,71,54,.85); color: white; }
.item-card-body { display: grid; gap: 6px; padding: 10px; }
.item-card-body > span { color: var(--muted); font-size: 12px; }
.item-card-body > strong { min-height: 42px; overflow: hidden; font-size: 15px; line-height: 1.45; }
.item-meta-line { min-height: 20px; color: var(--muted); font-size: 13px; }
.item-card button {
  min-height: 34px;
  padding: 0 7px;
  border-color: rgba(54,93,74,.23);
  background: #edf3ec;
  color: var(--green-dark);
  font-size: 14px;
}
.item-card.is-selected button { background: var(--green); color: white; }
.empty-state { grid-column: 1 / -1; padding: 60px 20px; color: var(--muted); text-align: center; }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
  padding-top: 17px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}
footer p { margin: 0; }

footer .ai-generation-notice {
  flex: 1 0 100%;
  padding: 11px 13px;
  border: 1px solid rgba(122, 89, 155, .24);
  border-radius: 11px;
  background: rgba(246, 239, 255, .72);
  color: #5d4773;
}

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 1fr; }
  .command-panel { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .command-panel > .panel-heading { grid-column: 1 / -1; }
}

@media (max-width: 850px) {
  .app-shell { padding: 16px 12px 24px; }
  .topbar { display: grid; }
  .topbar-actions { justify-content: flex-start; }
  .summary-strip { grid-template-columns: repeat(2,1fr); }
  .subscriber-notice { align-items: flex-start; flex-direction: column; }
  .preview-grid { grid-template-columns: 1fr; }
  .standing-preview { min-height: 430px; }
  .bar-preview { min-height: 0; }
  .standing-stage { width: min(215px, 38vw, 62%); }
  .selection-summary { grid-template-columns: 1fr; }
  .command-panel { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: 1fr; }
  .lookup-panel { grid-template-columns: 1fr; padding: 20px; }
}

@media (max-width: 520px) {
  .summary-strip { grid-template-columns: 1fr; }
  .preview-panel, .command-panel, .collection-panel { padding: 12px; }
  .standing-preview { min-height: 380px; }
  .bar-preview { min-height: 0; }
  .standing-stage { width: min(185px, 48vw, 62%); }
  .counter-front { height: 36.78%; }
  .nameplate-preview { width: min(220px, 40%); }
  .save-row { align-items: stretch; flex-direction: column; }
  .item-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .item-image-wrap { height: 132px; }
  .lookup-row { grid-template-columns: 1fr; }
}
