:root {
  --parchment: #e7d7b8;
  --parchment-deep: #d4c09a;
  --ink: #2a2118;
  --ink-soft: #5c4c3a;
  --brass: #9a7b3c;
  --brass-light: #c4a35a;
  --mahogany: #5c3a28;
  --mahogany-deep: #3d2418;
  --lamp: #f3e6c8;
  --crimson: #8b2e2e;
  --glass-blue: #3d6e8c;
  --glass-green: #3f6b4a;
  --glass-amber: #b07d2a;
  --glass-rose: #a14c5c;
  --glass-violet: #5c4d7a;
  --ok: #2f5d3a;
  --bad: #7a2e2e;
  --shadow: rgba(42, 33, 24, 0.28);
  --frame: #6b4a30;
  font-size: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background:
    radial-gradient(ellipse at 50% 0%, #f0e2c4 0%, var(--parchment) 55%, #cbb892 100%);
  color: var(--ink);
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

#app {
  width: 100%;
  height: 100%;
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
  gap: 8px;
}

.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--brass);
  background:
    conic-gradient(from 20deg, var(--glass-rose), var(--glass-amber), var(--glass-green), var(--glass-blue), var(--glass-violet), var(--glass-rose));
  box-shadow: inset 0 0 0 4px var(--parchment), 0 2px 0 var(--shadow);
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--mahogany-deep);
  line-height: 1.1;
}

.tagline {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  border: 1px solid rgba(154, 123, 60, 0.45);
  background: rgba(243, 230, 200, 0.55);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.dot { opacity: 0.5; }

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 8px;
}

.panel {
  background: linear-gradient(180deg, rgba(243, 230, 200, 0.72), rgba(212, 192, 154, 0.55));
  border: 1px solid rgba(92, 58, 40, 0.35);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 6px 16px var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mahogany);
  width: 100%;
  text-align: center;
}

.soft {
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink-soft);
}

.frame {
  position: relative;
  width: min(42vw, 220px);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid var(--frame);
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 11px,
      rgba(92, 58, 40, 0.05) 11px,
      rgba(92, 58, 40, 0.05) 12px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 11px,
      rgba(92, 58, 40, 0.05) 11px,
      rgba(92, 58, 40, 0.05) 12px
    ),
    var(--lamp);
  box-shadow:
    inset 0 0 0 1px rgba(196, 163, 90, 0.55),
    inset 0 0 24px rgba(90, 60, 30, 0.12),
    0 4px 0 rgba(61, 36, 24, 0.18);
  overflow: hidden;
}

.frame.lamp::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 40%, rgba(255, 244, 210, 0.35), transparent 68%);
  z-index: 1;
}

.frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.badge {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 2;
  background: rgba(47, 93, 58, 0.92);
  color: #f4efe2;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.3;
  min-height: 2em;
}

.plates-panel {
  grid-column: 1 / -1;
  align-items: stretch;
}

.tray {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;
  width: 100%;
  padding: 2px 0 4px;
}

.plate-card {
  width: 72px;
  min-width: 72px;
  min-height: 96px;
  border-radius: 10px;
  border: 2px solid rgba(92, 58, 40, 0.4);
  background: linear-gradient(180deg, #f7eccf, #e0cc9f);
  box-shadow: 0 2px 0 rgba(61, 36, 24, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  padding: 6px 4px 5px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

.plate-card:active {
  transform: scale(0.97);
}

.plate-card.selected {
  border-color: var(--brass);
  box-shadow: 0 0 0 2px rgba(196, 163, 90, 0.55), 0 4px 10px var(--shadow);
  transform: translateY(-2px);
}

.plate-card.locked {
  opacity: 0.72;
}

.plate-card canvas {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  border: 1px solid rgba(92, 58, 40, 0.25);
  background: var(--lamp);
  pointer-events: none;
}

.plate-meta {
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.15;
}

.plate-weight {
  position: absolute;
  inset: 4px 5px auto auto;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--brass);
  color: #f8efd8;
  font-size: 0.62rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.tray-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-block-start: 4px;
}

button {
  font-family: inherit;
  font-size: 0.86rem;
  border-radius: 10px;
  border: 1px solid rgba(92, 58, 40, 0.45);
  background: linear-gradient(180deg, #f4e6c4, #dfc896);
  color: var(--ink);
  padding: 12px 14px;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(61, 36, 24, 0.16);
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

button.primary {
  background: linear-gradient(180deg, #8d4d32, #6a3420);
  color: #f6e8c8;
  border-color: #4a2416;
  font-weight: 700;
  letter-spacing: 0.03em;
}

button.ghost {
  background: rgba(243, 230, 200, 0.45);
}

button.tool {
  flex: 1 1 auto;
  max-width: 140px;
  background: linear-gradient(180deg, #efe0b8, #d7c08d);
}

.dock {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-block-start: 2px;
}

.instructions {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--ink-soft);
  text-align: center;
  padding: 0 4px;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.actions button {
  flex: 1 1 120px;
  max-width: 220px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 33, 24, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
}

.overlay.hidden,
.hidden {
  display: none !important;
}

.modal {
  width: min(360px, 100%);
  background: linear-gradient(180deg, #f3e6c4, #dcc89a);
  border: 2px solid var(--brass);
  border-radius: 16px;
  padding: 22px 18px 16px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  position: relative;
}

.modal-ornament {
  width: 54px;
  height: 8px;
  margin: 0 auto 12px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--brass-light), transparent);
}

.modal h2 {
  margin: 0 0 8px;
  color: var(--mahogany-deep);
  font-size: 1.3rem;
}

.modal p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.4;
}

.modal .primary {
  width: 100%;
}

.feedback-ok { color: var(--ok) !important; font-weight: 700; }
.feedback-bad { color: var(--bad) !important; font-weight: 700; }
.feedback-info { color: var(--ink-soft) !important; }

@media (orientation: landscape) and (max-height: 520px) {
  #app { padding: 4px 8px; gap: 4px; }
  .tagline, .instructions { display: none; }
  .stage {
    grid-template-columns: 1fr 1fr 1.4fr;
    grid-template-rows: 1fr;
  }
  .plates-panel { grid-column: auto; }
  .frame { width: min(28vw, 160px); }
  .plate-card { width: 64px; min-width: 64px; min-height: 88px; }
  .plate-card canvas { width: 48px; height: 48px; }
  h1 { font-size: 1.05rem; }
  .hint { min-height: 1.2em; font-size: 0.68rem; }
}

@media (min-width: 720px) and (min-height: 700px) {
  .frame { width: 240px; }
  .plate-card { width: 84px; min-width: 84px; }
  .plate-card canvas { width: 64px; height: 64px; }
}
