:root {
  --gold: #f5cc5a;
  --parchment: #f8ecc7;
  --parchment-dark: #e6cfa0;
  --wood: #7a4b14;
  --ink: #291704;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0d1017;
  color: #f4f1e8;
  font-family: "PMingLiU", "MingLiU", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

#toolbar {
  height: 34px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #2b2217 0%, #1a140d 100%);
  border-bottom: 1px solid #6b4e24;
  font-size: 12px;
  flex-shrink: 0;
}

#toolbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

#toolbar .badge {
  background: linear-gradient(180deg, #ffe384, #c78610);
  color: #241302;
  font-weight: 800;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
}

#toolbar .sub {
  color: #b8a484;
  font-size: 11px;
}

#toolbar .controls {
  display: flex;
  gap: 5px;
}

.tb-btn {
  background: #3b2d1b;
  color: #f2e2c2;
  border: 1px solid #7a5c30;
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.tb-btn:hover { background: #523e24; }
.tb-btn.active {
  background: #8c5d19;
  border-color: #f5cc5a;
  color: #fffbe8;
}

#stage-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 45%, #1f1a14 0%, #090a0f 100%);
  overflow: hidden;
}

.viewport {
  position: relative;
  width: 640px;
  height: 480px;
  background: #000;
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.85), 0 0 0 3px #8c6326, 0 0 0 5px #2e1d08;
  transform-origin: center center;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 640px;
  height: 480px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#ui-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}

/* Classic Setup Screen over Panel.mkf[25] wallpaper */
#screen-setup {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-header.classic-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, rgba(248,236,199,0.95), rgba(226,200,145,0.95));
  border: 2px solid #8c5a14;
  border-radius: 6px;
  padding: 5px 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}
.setup-header h2 {
  margin: 0;
  font-size: 15px;
  color: #3d1f04;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.setup-box.classic-parchment {
  background: linear-gradient(180deg, rgba(252,243,214,0.94), rgba(235,213,164,0.94));
  border: 2px solid #8c5a14;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  color: #2b1804;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.setup-box h3 {
  margin: 0;
  font-size: 12px;
  color: #7d3e00;
  border-bottom: 1px solid #c29b50;
  padding-bottom: 3px;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.map-tile {
  background: #fff8e2;
  border: 1.5px solid #ad8844;
  border-radius: 4px;
  padding: 2px;
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: #3d2408;
}
.map-tile img {
  width: 100%;
  height: 44px;
  object-fit: cover;
  border-radius: 2px;
  display: block;
  margin-bottom: 2px;
}
.map-tile.selected {
  border: 2.5px solid #d9381e;
  background: #ffe999;
  color: #7d1400;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.char-chip {
  background: #fff8e2;
  border: 1.5px solid #ad8844;
  border-radius: 4px;
  padding: 3px;
  text-align: center;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  color: #2e1904;
  position: relative;
}
.char-chip img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 3px;
  display: block;
  margin: 0 auto 2px;
}
.char-chip.picked-human { border: 2px solid #189e44; background: #d6fce0; }
.char-chip.picked-ai { border: 2px solid #2b6be0; background: #dceaff; }
.char-chip .tag {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  padding: 0 3px;
  border-radius: 2px;
  font-weight: 800;
}
.char-chip.picked-human .tag { background: #189e44; color: #fff; }
.char-chip.picked-ai .tag { background: #2b6be0; color: #fff; }

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 700;
  gap: 6px;
}
.opt-row select, .opt-row input {
  background: #fffdf5;
  color: #241404;
  border: 1px solid #9c7532;
  border-radius: 3px;
  padding: 2px 5px;
  font-size: 11px;
}

/* Classic Comic Speech Bubble */
#speech-bubble {
  position: absolute;
  left: 10px;
  bottom: 34px;
  max-width: 348px;
  background: #fffdf2;
  color: #211507;
  border: 2.5px solid #8c5812;
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.58);
  font-size: 12px;
  font-weight: 700;
  z-index: 30;
  pointer-events: auto;
  cursor: pointer;
}
#speech-bubble img {
  width: 44px;
  height: 44px;
  border-radius: 4px;
  border: 1.5px solid #8a5c14;
  object-fit: cover;
  flex-shrink: 0;
}

/* Classic Modal Layer */
#modal-layer {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 50;
  padding: 10px;
}

.r4-modal {
  background: linear-gradient(180deg, #2d383c 0%, #182224 100%);
  border: 3px solid #d9a43c;
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.85);
  color: #f8f2df;
  max-width: 612px;
  max-height: 456px;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.r4-modal.compact { max-width: 400px; }
.r4-modal.parchment {
  background: linear-gradient(180deg, #faf0d2 0%, #ebd6a2 100%);
  border-color: #966016;
  color: #2b1704;
}

.r4-modal-hdr {
  background: linear-gradient(90deg, #7a480d, #c78b22, #7a480d);
  color: #fffbe8;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.65);
}
.r4-modal-close {
  background: rgba(0,0,0,0.38);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 3px;
  padding: 1px 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.r4-modal-body {
  padding: 10px 12px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.45;
  flex: 1;
}
.r4-modal-ftr {
  padding: 7px 12px;
  background: rgba(0, 0, 0, 0.14);
  border-top: 1px solid rgba(160, 112, 34, 0.35);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.r4-btn {
  background: linear-gradient(180deg, #ffe58f, #d48e16);
  color: #241202;
  border: 1.5px solid #fff2be;
  border-bottom-color: #7d4a05;
  border-radius: 4px;
  padding: 5px 12px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}
.r4-btn.secondary {
  background: linear-gradient(180deg, #5c6878, #37404c);
  color: #f4f6fa;
  border-color: #9ba8ba;
}
.r4-btn.danger {
  background: linear-gradient(180deg, #eb5757, #a62121);
  color: #fff;
  border-color: #ff9c9c;
}
.r4-btn:hover { filter: brightness(1.08); }
.r4-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.r4-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.r4-table th, .r4-table td {
  padding: 4px 5px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  text-align: left;
}
.r4-table th {
  color: #ffe280;
  background: rgba(0,0,0,0.35);
  position: sticky;
  top: 0;
}
.r4-table.light th {
  background: rgba(140, 92, 20, 0.2);
  color: #6b3800;
}
.r4-table.light td { border-bottom-color: rgba(140, 92, 20, 0.25); }
.r4-table tr:hover td { background: rgba(255,255,255,0.08); }
.r4-table tr.selected td { background: rgba(245, 204, 90, 0.25); }

.up { color: #ff5b5b; font-weight: 800; }
.down { color: #3ee074; font-weight: 800; }

.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.tab-btn {
  background: #42331f;
  color: #ebdcb8;
  border: 1px solid #967035;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11.5px;
  cursor: pointer;
}
.tab-btn.active {
  background: #e09f24;
  color: #211102;
  border-color: #fff0b8;
  font-weight: 800;
}

.dice-opt {
  background: #362a1a;
  color: #f5e6c4;
  border: 1px solid #8a6936;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 10.5px;
  cursor: pointer;
}
.dice-opt.active {
  background: #e3a726;
  color: #1f1202;
  font-weight: 800;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.card-item.classic-slot {
  background: linear-gradient(180deg, #4b6e66 0%, #314d47 100%);
  border: 2px solid #a8c7be;
  border-bottom-color: #1c2e2a;
  border-radius: 5px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  gap: 6px;
  align-items: center;
  color: #fff7e0;
}
.card-item.classic-slot:hover { border-color: #ffe270; filter: brightness(1.1); }
.card-item img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.classic-card-badge {
  width: 30px;
  height: 36px;
  border-radius: 4px;
  background: linear-gradient(180deg, #fff5cc, #e3aa30);
  border: 2px solid #854d08;
  color: #542200;
  font-weight: 900;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}
.card-item .ci-name { font-weight: 800; font-size: 11.5px; color: #fff0b3; }
.card-item .ci-meta { font-size: 10px; color: #d1e8e0; }

.lotto-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.lotto-num {
  background: #422618;
  color: #fff2cc;
  border: 1.5px solid #c9923c;
  border-radius: 4px;
  padding: 6px 0;
  text-align: center;
  font-weight: 800;
  cursor: pointer;
}
.lotto-num:hover { background: #6b3d24; }
.lotto-num.taken { background: #291815; color: #8c6a64; cursor: not-allowed; }
.lotto-num.mine { background: #e8a725; color: #241000; border-color: #fff2be; }

.event-illus {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.event-illus img {
  width: 170px;
  height: 112px;
  object-fit: cover;
  border-radius: 5px;
  border: 2px solid #8c5a12;
  flex-shrink: 0;
}

.minigame-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#minigame-canvas {
  border: 2px solid #e6b84c;
  border-radius: 4px;
  background: #0d1629;
  image-rendering: pixelated;
  cursor: crosshair;
}
