* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, #f4e4cb 0%, #d9b98a 100%);
  color: #3b2b1a;
  min-height: 100vh;
  padding: 16px;
}
.container {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
header {
  grid-column: 1 / -1;
  text-align: center;
  padding: 12px;
  background: rgba(255,255,255,0.45);
  border-radius: 10px;
}
header h1 { font-size: 26px; margin-bottom: 4px; font-family: "Courier New", monospace; letter-spacing: 2px; }
header .subtitle { font-size: 13px; opacity: 0.75; }
canvas.pixel {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}
.hud-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.hud-item {
  background: rgba(59, 43, 26, 0.82);
  color: #f4e4cb;
  border-radius: 6px;
  padding: 4px 10px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: "Courier New", monospace;
}
.hud-lbl {
  font-size: 10px;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.hud-num { font-size: 14px; font-weight: bold; }
.sticky-head {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f4e4cb;
  padding: 6px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scene {
  display: block;
  width: 100%;
  height: auto;
  background: #d9b98a;
  border: 4px solid #5c3b1c;
  border-radius: 6px;
}
.shop {
  grid-column: 1 / -1;
  background: rgba(255,255,255,0.55);
  border-radius: 10px;
  padding: 12px;
  max-height: 560px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #c8a878;
  background: rgba(255,255,255,0.55);
  border-radius: 10px;
  padding: 4px 8px 0;
}
.tab {
  flex: 1;
  background: transparent;
  color: #6b4a2b;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  transition: color 100ms, border-color 100ms;
}
.tab:hover { color: #3b2b1a; }
.tab.active {
  color: #3b2b1a;
  border-bottom-color: #8b5a2b;
}
.tab-content { flex: 1; min-height: 0; }
.tab-content.hidden { display: none; }

/* ── 주식 모드: 기본 탭/컨텐츠는 숨기고 stock-panel 만 노출 ── */
.stock-panel { display: none; }
.container.stock-mode .tabs,
.container.stock-mode .tab-content { display: none !important; }
.container.stock-mode .stock-panel { display: flex; flex-direction: column; gap: 8px; }

.stock-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 6px 8px;
  background: #1b2430;
  color: #f1c40f;
  border-radius: 6px;
  font-family: "Courier New", monospace;
  font-size: 13px;
  font-weight: bold;
  flex-wrap: wrap;
}
.stock-panel-head .stock-panel-hint {
  color: #95a5a6;
  font-weight: normal;
  font-size: 11px;
}
.stock-row {
  background: #0e1c2a;
  border: 2px solid #2c3e50;
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 6px 10px;
  align-items: center;
  color: #ecf0f1;
  font-family: "Courier New", monospace;
  transition: border-color 100ms, background 100ms;
}
.stock-row.active {
  border-color: #f1c40f;
  background: #14283a;
  box-shadow: 0 0 0 1px #f1c40f33 inset;
}
.stock-row .swatch {
  width: 10px;
  height: 46px;
  border-radius: 2px;
}
.stock-row .body .name { font-weight: bold; font-size: 14px; }
.stock-row .body .sym { font-size: 10px; color: #7f8c8d; }
.stock-row .body .hold { font-size: 11px; color: #bdc3c7; margin-top: 2px; }
.stock-row .body .pnl { font-size: 11px; margin-top: 2px; }
.stock-row .body .pnl.up { color: #2ecc71; }
.stock-row .body .pnl.down { color: #e74c3c; }
.stock-row .price {
  text-align: right;
  min-width: 88px;
}
.stock-row .price .val { font-size: 13px; font-weight: bold; }
.stock-row .price .chg { font-size: 11px; margin-top: 2px; }
.stock-row .price .chg.up { color: #2ecc71; }
.stock-row .price .chg.down { color: #e74c3c; }
.stock-row .btns {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 280px;
}
.stock-row .btn-row { display: flex; gap: 4px; }
.stock-row .btn-row.bulk button,
.stock-row .btn-row.step button { flex: 1 1 0; min-width: 0; }
.stock-row .btn-row.custom .qty {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 6px 8px;
  border: 1px solid #0a0a0a;
  border-radius: 4px;
  background: #0b1d2e;
  color: #ecf0f1;
  font-family: inherit;
  font-size: 12px;
}
.stock-row .btn-row.custom .qty::placeholder { color: #7f8c8d; }
.stock-row .btn-row.custom button { flex: 0 0 56px; }
.stock-row .btns button {
  appearance: none;
  -webkit-appearance: none;
  padding: 6px 4px;
  border: 1px solid #0a0a0a;
  border-radius: 4px;
  color: #ffffff;
  font-family: inherit;
  font-weight: bold;
  font-size: 11px;
  line-height: 1.15;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 100ms, transform 80ms, filter 100ms;
}
.stock-row .btns button:active:not(:disabled) { transform: translateY(1px); }
.stock-row .btns button:disabled {
  background: #2c3e50 !important;
  color: #7f8c8d !important;
  border-color: #1b2530 !important;
  cursor: not-allowed;
  opacity: 0.75;
}
/* 매도: 빨강 계열 (전량 → -10 순으로 진함) */
.stock-row .btns .sell-all  { background: #7b1c14; border-color: #f1c40f; color: #fff5e6; }
.stock-row .btns .sell-half { background: #a02820; border-color: #f1c40f; color: #fff5e6; }
.stock-row .btns .sell      { background: #c0392b; }
/* 매수: 초록 계열 (+10 → 전량 순으로 진함) */
.stock-row .btns .buy       { background: #27ae60; }
.stock-row .btns .buy-half  { background: #1f8a4c; border-color: #f1c40f; color: #f0fff5; }
.stock-row .btns .buy-all   { background: #145a32; border-color: #f1c40f; color: #f0fff5; }
.stock-row .btns button:hover:not(:disabled) { filter: brightness(1.12); }

@media (max-width: 560px) {
  .stock-row { grid-template-columns: 8px 1fr; grid-template-rows: auto auto auto; padding: 6px 8px; }
  .stock-row .swatch { grid-row: span 3; height: auto; }
  .stock-row .price { grid-column: 2; text-align: left; }
  .stock-row .btns { grid-column: 1 / -1; min-width: 0; }
  .stock-row .btn-row.step { flex-wrap: wrap; }
  .stock-row .btn-row.step button { flex: 1 1 22%; }
  .stock-row .btns button { font-size: 10px; padding: 5px 2px; }
  .stock-row .btn-row.custom button { flex: 0 0 48px; }
}
.tool-card, .painting-card {
  background: #fff9f0;
  border: 1px solid #c8a878;
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 100ms;
}
.tool-card:hover:not(.locked):not(.cannot):not(.owned),
.painting-card:hover:not(.locked):not(.cannot):not(.owned) { background: #fff3dc; }
.tool-card.cannot, .painting-card.cannot { opacity: 0.6; cursor: not-allowed; }
.tool-card.locked, .painting-card.locked { opacity: 0.35; cursor: not-allowed; filter: grayscale(1); }
.tool-card.hidden, .painting-card.hidden, .gen.hidden { display: none !important; }
.tool-card.owned, .painting-card.owned { background: #e8f5e9; border-color: #81b489; cursor: default; opacity: 0.9; }
.tool-card canvas {
  width: 56px;
  height: 56px;
  background: #c9a97a;
  border: 2px solid #5c3b1c;
  border-radius: 4px;
  flex-shrink: 0;
}
.painting-card canvas {
  width: 112px;
  height: 56px;
  background: #c9a97a;
  border: 2px solid #5c3b1c;
  border-radius: 4px;
  flex-shrink: 0;
}
.tool-card .body, .painting-card .body { flex: 1; min-width: 0; }
.tool-card .name, .painting-card .name { font-weight: bold; font-size: 14px; }
.tool-card .stat, .painting-card .stat { font-size: 11px; opacity: 0.7; }
.tool-card .price, .painting-card .price { font-size: 13px; color: #b86a00; font-weight: bold; }
.tool-card .badge, .painting-card .badge {
  font-size: 11px;
  font-weight: bold;
  color: #2e7d32;
}
.gen {
  background: #fff9f0;
  border: 1px solid #c8a878;
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 100ms;
}
.gen:hover:not(.locked):not(.cannot) { background: #fff3dc; }
.gen.cannot { opacity: 0.6; cursor: not-allowed; }
.gen.locked { opacity: 0.35; cursor: not-allowed; filter: grayscale(1); }
.gen-canvas {
  width: 56px;
  height: 56px;
  background: #c9a97a;
  border: 2px solid #5c3b1c;
  border-radius: 4px;
  flex-shrink: 0;
}
.gen .body { flex: 1; min-width: 0; }
.gen .name { font-weight: bold; font-size: 14px; }
.gen .prod { font-size: 11px; opacity: 0.7; }
.gen .price { font-size: 13px; color: #b86a00; font-weight: bold; }
.gen .count {
  font-size: 22px;
  font-weight: bold;
  opacity: 0.45;
  min-width: 32px;
  text-align: right;
  font-family: "Courier New", monospace;
}
.actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 8px;
}
.mini-btn {
  background: #8b5a2b;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.mini-btn.warn { background: #c0392b; }
.mini-btn:hover { opacity: 0.88; }
@media (max-width: 560px) {
  body { padding: 8px; }
  .container { grid-template-columns: 1fr; gap: 10px; }
  header { padding: 8px; }
  header h1 { font-size: 20px; letter-spacing: 1px; }
  header .subtitle { font-size: 11px; }
  .hud-row { gap: 6px; }
  .hud-item { padding: 3px 8px; gap: 4px; }
  .hud-lbl { font-size: 9px; letter-spacing: 0.5px; }
  .hud-num { font-size: 12px; }
  .tab { font-size: 11px; padding: 6px 2px; }
  .shop { max-height: none; padding: 10px; }
  .gen { padding: 6px; gap: 8px; }
  .gen-canvas { width: 44px; height: 44px; }
  .gen .name { font-size: 13px; }
  .gen .prod { font-size: 10px; }
  .gen .price { font-size: 12px; }
  .gen .count { font-size: 18px; min-width: 24px; }
}
.pop {
  position: absolute;
  pointer-events: none;
  color: #ffeb8f;
  font-weight: bold;
  font-size: 18px;
  text-shadow: 1px 1px 0 #3b2b1a;
  animation: rise 800ms ease-out forwards;
  font-family: "Courier New", monospace;
}
@keyframes rise {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-50px); }
}
