:root {
  --brand-orange: #fd7702;
  --brand-orange-soft: #ffb36b;
  --brand-red: #ed2b24;
  --ink-900: #252321;
  --ink-700: #5e6673;
  --ink-500: #8b95a3;
  --bg-app: #f3f5f8;
  --bg-panel: #ffffff;
  --bg-panel-soft: #fafbfd;
  --line: #dfe4ec;
  --line-strong: #cfd6e2;
  --text-main: #2b3240;
  --text-dim: #677284;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  color: var(--text-main);
  font-family: "Inter", "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 420px at 10% -20%, rgba(253, 119, 2, 0.14), transparent 70%),
    radial-gradient(900px 340px at 95% 0%, rgba(237, 43, 36, 0.07), transparent 72%),
    var(--bg-app);
}

.app-shell {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 14px;
  position: relative;
  border-radius: 16px;
  --chaos-invert: 0;
  --chaos-hue-rotate: 0deg;
  --chaos-saturate: 1;
  --chaos-contrast: 1;
  --chaos-brightness: 1;
  filter:
    invert(var(--chaos-invert))
    hue-rotate(var(--chaos-hue-rotate))
    saturate(var(--chaos-saturate))
    contrast(var(--chaos-contrast))
    brightness(var(--chaos-brightness));
  transition: filter 220ms linear;
}

body.chaos-dark {
  background: linear-gradient(180deg, #080b10, #0d121a);
}

.app-shell.chaos-dark-theme {
  --bg-panel: #121823;
  --bg-panel-soft: #171f2d;
  --line: #2a3446;
  --line-strong: #3a4860;
  --text-main: #edf2fa;
  --text-dim: #b9c4d5;
  --ink-900: #f3f6fc;
  --ink-700: #c7d1de;
  filter: none;
}

.topbar {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(27, 38, 59, 0.06);
  padding: 12px 14px;
}

.brand-block h1 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.2rem, 2.5vw, 1.85rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink-900);
}

.brand-block {
  padding-left: 10px;
}

.brand-block h1 a {
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
}

.brand-block h1 a:focus-visible {
  outline: 2px solid rgba(253, 119, 2, 0.45);
  outline-offset: 2px;
}

.brand-block h1 img {
  width: 92px;
  height: auto;
  flex: 0 0 auto;
}

.brand-block p {
  display: none;
}

.mode-btn {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-panel-soft);
  color: var(--text-main);
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.mode-btn[aria-pressed="true"] {
  border-color: var(--brand-orange);
  background: #fff6ee;
}

.mode-btn:focus-visible {
  outline: 2px solid rgba(253, 119, 2, 0.48);
  outline-offset: 2px;
}

.hud {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.hud span {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-panel-soft);
  font-size: 0.89rem;
}

.hud strong {
  color: var(--text-dim);
  font-weight: 600;
}

.hud b {
  color: var(--text-main);
}

.game-wrap {
  margin-top: 12px;
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  box-shadow: 0 16px 34px rgba(27, 38, 59, 0.08);
}

.game-wrap.awakened {
  box-shadow: 0 20px 40px rgba(27, 38, 59, 0.12);
  border-color: #d8dee8;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: min(52vh, 560px);
}

.complaint-dock {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid #e8c6c2;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff7f6, #fff0ee);
  box-shadow: 0 10px 24px rgba(126, 36, 21, 0.14);
}

.complaint-dock.hidden {
  display: none;
}

.complaint-dock.ringing {
  animation: ringPulse 1s ease-in-out infinite;
}

.complaint-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.complaint-copy strong {
  color: #9b231b;
}

.complaint-copy span {
  color: #7f4e49;
  font-size: 0.88rem;
}

.complaint-dock button {
  border: 1px solid #e0afaa;
  border-radius: 10px;
  background: #fff;
  color: #6d2f2a;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
}

.complaint-dock button:hover {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 2px rgba(237, 43, 36, 0.12);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(250, 252, 255, 0.92));
}

.overlay.hidden {
  display: none;
}

.overlay.gameover {
  animation: fadeWake 0.36s ease-out;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3.4vw, 2rem);
  color: var(--ink-900);
  font-weight: 800;
}

.overlay p {
  margin: 0;
  color: var(--text-dim);
}

.hint {
  color: #9a4300;
  font-weight: 600;
}

.meta-note {
  color: #7d8795;
  font-size: 0.86rem;
  font-weight: 500;
}

.meta-note strong {
  color: #495465;
  font-weight: 700;
}

.micro-note {
  margin-top: 2px;
  color: #8f98a5;
  font-size: 0.78rem;
}

.mobile {
  color: #5f748f;
  font-size: 0.9rem;
}

.result-grid {
  margin: 8px auto;
  width: min(840px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 1fr));
  gap: 8px;
}

.result-grid div {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-grid span {
  color: var(--ink-700);
}

.actions {
  margin-top: 2px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.actions button,
.actions a {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text-main);
  text-decoration: none;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.actions button:hover,
.actions a:hover {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 2px rgba(253, 119, 2, 0.12);
}

.actions button:focus-visible,
.actions a:focus-visible,
.complaint-dock button:focus-visible,
.quick-btn:focus-visible,
.pack-controls button:focus-visible {
  outline: 2px solid rgba(253, 119, 2, 0.48);
  outline-offset: 2px;
}

#gameCanvas:focus-visible {
  outline: 2px solid rgba(253, 119, 2, 0.55);
  outline-offset: -2px;
}

.controls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-panel);
  padding: 10px;
}

.controls p {
  margin: 0;
  border: 1px solid var(--line);
  background: var(--bg-panel-soft);
  border-radius: 10px;
  padding: 7px 9px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.controls strong {
  color: var(--text-main);
}

.product-packbar {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-panel);
  padding: 10px;
}

.quick-selects {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.quick-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-panel-soft);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.quick-group strong {
  color: var(--text-main);
  font-size: 0.84rem;
}

.quick-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(64px, 1fr));
  gap: 6px;
}

.quick-btn {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: #4b5567;
  padding: 5px 8px;
  display: grid;
  gap: 2px;
  justify-items: center;
  cursor: pointer;
}

.quick-btn span {
  font-size: 0.73rem;
  color: #8892a1;
  font-weight: 600;
}

.quick-btn b {
  font-size: 0.9rem;
  color: #344054;
}

.quick-btn:hover {
  border-color: var(--brand-orange);
}

.quick-btn.active {
  border-color: var(--brand-orange);
  background: #fff6ee;
  box-shadow: 0 0 0 2px rgba(253, 119, 2, 0.12);
}

.quick-btn.required {
  border-color: #e9c7aa;
  background: #fff9f4;
}

.quick-btn.ok {
  border-color: #9fd0b1;
  background: #f3fbf6;
}

.quick-btn.bad {
  border-color: #efc1be;
  background: #fff5f4;
}

.quick-buttons-submit {
  grid-template-columns: 1fr;
}

.quick-btn-submit {
  min-height: 44px;
}

.product-packbar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.product-packbar-head strong {
  color: var(--text-main);
}

.product-packbar-head span {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.product-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
}

.product-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-panel-soft);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.product-card strong {
  color: var(--text-main);
  font-size: 0.9rem;
}

.product-card .meta {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.product-counts {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.8rem;
}

.product-counts b {
  color: #4d5768;
}

.pack-controls {
  display: flex;
  gap: 6px;
}

.pack-controls button {
  flex: 1;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: #4c586b;
  padding: 4px 6px;
  cursor: pointer;
  font-weight: 700;
}

.pack-controls button:hover {
  border-color: var(--brand-orange);
}

.product-card.ok {
  border-color: #9fd0b1;
  background: #f3fbf6;
}

.product-card.bad {
  border-color: #efc1be;
  background: #fff5f4;
}

.domain-footnote {
  margin: 10px 0 2px;
  text-align: center;
  color: #a0aab8;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

@media (max-width: 920px) {
  .result-grid,
  .controls {
    grid-template-columns: 1fr;
  }

  .product-list {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .quick-selects {
    grid-template-columns: 1fr;
  }

  .hud span {
    font-size: 0.84rem;
  }

  .complaint-dock {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 1240px) {
  .quick-selects {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .product-list {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }
}

@media (max-width: 1040px) {
  .brand-block h1 {
    font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  }

  .brand-block h1 img {
    width: 82px;
  }

  .mode-btn {
    order: 3;
  }

  .hud span {
    padding: 6px 10px;
    font-size: 0.83rem;
  }

  .product-list {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}

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

  .topbar {
    padding: 10px;
  }

  .brand-block {
    padding-left: 4px;
  }

  .brand-block h1 {
    gap: 8px;
    font-size: clamp(0.98rem, 4vw, 1.2rem);
  }

  .brand-block h1 img {
    width: 72px;
  }

  .hud {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-panel-soft);
    width: 100%;
  }

  .mode-btn {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.74rem;
  }

  .hud span {
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    padding: 5px 7px;
    font-size: 0.75rem;
    line-height: 1.18;
  }

  .hud span:nth-child(2n) {
    border-right: 0;
  }

  .hud span:nth-child(n + 3) {
    border-bottom: 0;
  }

  .quick-selects,
  .product-list,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .overlay {
    padding: 14px;
    gap: 8px;
  }

  .overlay h2 {
    font-size: clamp(1.02rem, 4.6vw, 1.34rem);
  }

  .overlay p {
    font-size: 0.95rem;
  }

  .result-grid div {
    padding: 8px 10px;
  }

  .result-grid span {
    font-size: 0.92rem;
  }

  .result-grid b {
    font-size: 1.02rem;
  }

  .meta-note {
    font-size: 0.8rem;
  }

  .hint {
    font-size: 0.92rem;
  }

  .micro-note {
    font-size: 0.72rem;
  }

  .quick-group,
  .product-card {
    padding: 7px;
  }

  .domain-footnote {
    font-size: 0.7rem;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 8px 9px;
    gap: 8px;
  }

  .brand-block {
    padding-left: 2px;
  }

  .brand-block h1 {
    font-size: clamp(0.9rem, 4.3vw, 1.08rem);
    gap: 6px;
    line-height: 1.15;
  }

  .brand-block h1 img {
    width: 58px;
  }

  .hud {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    width: 100%;
  }

  .hud span {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-panel-soft);
    padding: 4px 7px;
    font-size: 0.7rem;
    line-height: 1.12;
    white-space: nowrap;
  }

  .hud strong,
  .hud b {
    color: #364254;
    font-weight: 700;
  }

  .overlay p {
    font-size: 0.92rem;
    color: #5b687b;
  }

  .hint {
    font-size: 0.88rem;
    color: #7f3f06;
  }

  .overlay {
    display: block;
    overflow-y: auto;
    padding: 10px;
  }

  .overlay > * + * {
    margin-top: 6px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .actions button,
  .actions a {
    padding: 8px 10px;
    font-size: 0.86rem;
    text-align: center;
  }
}

@media (max-width: 430px) {
  .brand-block h1 {
    font-size: clamp(0.84rem, 4.1vw, 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-wrap,
  .overlay.gameover,
  .complaint-dock.ringing {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes ringPulse {
  0%,
  100% {
    box-shadow: 0 10px 24px rgba(126, 36, 21, 0.14);
  }
  50% {
    box-shadow: 0 14px 28px rgba(237, 43, 36, 0.24);
  }
}

@keyframes fadeWake {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
