* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: #0f0f1a;
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

button,
.card-btn,
.menu {
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

#app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  height: 100vh;
  min-height: 0;
}

#panel-left,
#panel-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #14141f;
  border-color: #2a2a38;
  z-index: 10;
}

#panel-left {
  border-right: 1px solid #2a2a38;
}

#panel-right {
  border-left: 1px solid #2a2a38;
}

#panel-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0077be;
}

#game-root {
  flex: 1;
  min-height: 0;
  position: relative;
}

#game-root canvas {
  display: block;
}

.panel-section {
  padding: 12px;
}

.panel-hand,
.panel-tools {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #2a2a38;
}

.panel-title {
  color: #8a8a9a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.panel-title-row .panel-title {
  margin-bottom: 0;
}

.draw-packs,
.tool-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pack-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: #1e1e2c;
  border: 2px solid #3a3a4e;
  border-radius: 8px;
  color: #eee;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.pack-btn:hover:not(:disabled) {
  background: #2a2a3e;
  border-color: #6cf;
}

.pack-btn:disabled {
  background: #181822;
  border-color: #2e2e3a;
  color: #666;
  cursor: not-allowed;
}

.pack-btn.last:not(:disabled) {
  box-shadow: 0 0 0 1px rgba(102, 204, 255, 0.35);
}

.pack-btn.draw-ready:not(:disabled) {
  border-color: #8cf;
}

.pack-btn.biome-meadow { border-color: #3a5a3a; background: #1a241a; }
.pack-btn.biome-meadow:hover:not(:disabled) { background: #243024; border-color: #8c8; }
.pack-btn.biome-forest { border-color: #2a4a2a; background: #152015; }
.pack-btn.biome-forest:hover:not(:disabled) { background: #1e301e; border-color: #8c8; }
.pack-btn.biome-desert { border-color: #6a4a28; background: #241c14; }
.pack-btn.biome-desert:hover:not(:disabled) { background: #322818; border-color: #e0b060; }
.pack-btn.biome-harbor { border-color: #2a4a6a; background: #141c28; }
.pack-btn.biome-harbor:hover:not(:disabled) { background: #1c2838; border-color: #6cf; }

.pack-btn .pack-name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pack-btn .pack-meta {
  color: #9ab;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.pack-btn:disabled .pack-meta {
  color: #666;
}

.trash-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.trash-row .trash-btn {
  width: 100%;
}

.tool-btn .key-hint,
.trash-btn .key-hint {
  margin-left: auto;
}

#hud {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  color: #e0e0e0;
  font-size: 14px;
  padding: 8px 12px;
  background: rgba(15, 15, 26, 0.88);
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
}

.menu {
  position: relative;
}

.menu-toggle {
  width: 100%;
  background: transparent;
  border: 1px solid #555;
  border-radius: 6px;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 8px 10px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.menu-toggle:hover,
.menu-toggle[aria-expanded="true"] {
  border-color: #6cf;
  color: #fff;
  background: #252538;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 0;
  background: #1a1a28;
  border: 1px solid #444;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-dropdown.hidden {
  display: none;
}

.menu-dropdown button {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #ddd;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 10px;
  text-align: left;
}

.menu-dropdown button:hover {
  background: #2a2a3e;
  color: #fff;
}

.menu-dropdown .menu-danger {
  color: #faa;
}

.menu-dropdown .menu-danger:hover {
  background: #3a2020;
  color: #fcc;
}

.menu-sep {
  height: 1px;
  background: #333;
  margin: 4px 2px;
}

.reset-btn {
  background: transparent;
  border: 1px solid #555;
  border-radius: 6px;
  color: #aaa;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  transition: border-color 0.15s, color 0.15s;
}

.reset-btn:hover {
  border-color: #f66;
  color: #f88;
}

.shop-btn,
.tool-btn,
.trash-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-text {
  white-space: nowrap;
}

.btn-cost {
  opacity: 0.9;
  white-space: nowrap;
}

.key-hint {
  background: #1a1a24;
  border: 1px solid #555;
  border-radius: 4px;
  color: #9ab;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  margin-left: 2px;
  padding: 2px 5px;
}

.shop-btn {
  background: #2a4a2e;
  border: 2px solid #4a8a4e;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  transition: border-color 0.15s, background 0.15s;
}

.shop-btn:hover:not(:disabled) {
  background: #356035;
  border-color: #6cf;
}

.shop-btn:disabled {
  background: #222;
  border-color: #444;
  color: #666;
  cursor: not-allowed;
}

.shop-btn.draw-ready:not(:disabled) {
  border-color: #8cf;
  box-shadow: 0 0 0 1px rgba(102, 204, 255, 0.25);
}

.draw-hand-range {
  color: #bdf;
  font-weight: 500;
}

.draw-hand-price {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.price-was {
  color: #888;
  font-size: 12px;
  text-decoration: line-through;
}

.price-now {
  color: #ffd;
  font-weight: 700;
}

.price-badge {
  background: #3a5a2a;
  border: 1px solid #6a8a4a;
  border-radius: 4px;
  color: #cf9;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  text-transform: uppercase;
}

.trash-btn {
  background: #3a2020;
  border: 2px solid #6a3030;
  border-radius: 6px;
  color: #faa;
  cursor: pointer;
  font-size: 13px;
  padding: 6px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.trash-btn:hover:not(:disabled) {
  background: #4a2828;
  border-color: #f66;
}

.trash-btn.bulk {
  font-size: 12px;
  padding: 6px 10px;
}

.trash-btn:disabled {
  background: #222;
  border-color: #444;
  color: #555;
  cursor: not-allowed;
}

.tool-btn {
  width: 100%;
  background: #3a3020;
  border: 2px solid #6a5a30;
  border-radius: 6px;
  color: #fd8;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 10px;
  transition: border-color 0.15s, background 0.15s;
}

.tool-btn:hover:not(:disabled) {
  background: #4a3828;
  border-color: #fc6;
}

.tool-btn:disabled {
  background: #222;
  border-color: #444;
  color: #666;
  cursor: not-allowed;
}

.tool-btn.selected {
  border-color: #fc6;
  background: #5a4020;
}

.tool-btn.bulldoze {
  background: #3a2028;
  border-color: #6a3040;
  color: #faa;
}

.tool-btn.bulldoze:hover:not(:disabled) {
  background: #4a2830;
  border-color: #f66;
}

.tool-btn.bulldoze.selected {
  border-color: #f88;
  background: #5a2830;
}

.tool-btn.cut {
  background: #203a28;
  border-color: #306a40;
  color: #afa;
}

.tool-btn.cut:hover:not(:disabled) {
  background: #284a30;
  border-color: #6c6;
}

.tool-btn.cut.selected {
  border-color: #8c8;
  background: #305a38;
}

#hand-count {
  color: #888;
  font-size: 12px;
  transition: color 0.15s;
}

#hand-count.hand-can-draw {
  color: #8c8;
}

#hand-count.hand-busy {
  color: #ca8;
}

#hand-count.hand-near-full {
  color: #f88;
}

#wallet {
  color: #888;
  font-size: 13px;
}

#hand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.card-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #2a2a3e;
  border: 2px solid #444;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  padding: 7px 10px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.card-btn:hover {
  background: #353550;
  border-color: #666;
}

.card-btn.selected {
  border-color: #6cf;
  background: #2a3a4e;
}

.card-btn.biome-forest {
  border-color: #3a5a3a;
  background: #1e2e1e;
}

.card-btn.biome-forest:hover {
  background: #2a3e2a;
  border-color: #5a8a5a;
}

.card-btn.biome-forest.selected {
  border-color: #8c8;
  background: #2a4a2a;
}

.card-btn.biome-harbor {
  border-color: #3a5a7a;
  background: #1e2a3a;
}

.card-btn.biome-harbor:hover {
  background: #2a3a4e;
  border-color: #5a8aba;
}

.card-btn.biome-harbor.selected {
  border-color: #6cf;
  background: #2a3a4e;
}

.card-btn.biome-desert {
  border-color: #7a5a30;
  background: #2a2218;
}

.card-btn.biome-desert:hover {
  background: #3a2e1e;
  border-color: #c49a62;
}

.card-btn.biome-desert.selected {
  border-color: #e0b060;
  background: #3a2e1e;
}

#hint,
.status-line {
  color: #cde;
  font-size: 12px;
  min-height: 1.2em;
  padding: 6px 12px;
  background: rgba(15, 15, 26, 0.88);
  border-top: 1px solid rgba(0, 0, 0, 0.25);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-box {
  position: relative;
  background: #1e1e2e;
  border: 1px solid #444;
  border-radius: 10px;
  max-width: 360px;
  padding: 24px;
  width: calc(100% - 32px);
}

.modal-box h2 {
  color: #eee;
  font-size: 18px;
  margin-bottom: 10px;
}

.modal-box p {
  color: #999;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-box-wide {
  max-width: 520px;
}

.save-code {
  background: #12121c;
  border: 1px solid #444;
  border-radius: 6px;
  color: #ccc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 10px;
  padding: 10px;
  resize: vertical;
  width: 100%;
}

.save-modal-status {
  color: #8c8;
  font-size: 12px;
  margin-bottom: 12px;
  min-height: 1.2em;
}

.save-modal-status.error {
  color: #f88;
}

.modal-btn.import {
  background: #2a4a2e;
  border-color: #4a8a4e;
  color: #cfc;
}

.modal-btn.import:hover {
  background: #356035;
  border-color: #6cf;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.modal-btn {
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
}

.modal-btn.cancel {
  background: #2a2a3e;
  border: 1px solid #555;
  color: #ccc;
}

.modal-btn.cancel:hover {
  background: #353550;
}

.modal-btn.confirm {
  background: #5a2020;
  border: 1px solid #a33;
  color: #faa;
}

.modal-btn.confirm:hover {
  background: #6a2828;
  border-color: #f66;
}

#log-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 420px;
  max-height: 240px;
  z-index: 20;
  background: rgba(15, 15, 26, 0.95);
  border: 1px solid #444;
  border-radius: 8px 0 0 0;
  display: flex;
  flex-direction: column;
}

#log-panel.hidden {
  display: none;
}

#log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid #333;
  color: #aaa;
  font-size: 12px;
}

#log-actions {
  display: flex;
  gap: 6px;
}

.log-btn {
  background: #2a2a3e;
  border: 1px solid #555;
  border-radius: 4px;
  color: #ccc;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 8px;
}

.log-btn:hover {
  background: #353550;
}

#log-output {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  margin: 0;
  font-size: 10px;
  line-height: 1.4;
  color: #8a8;
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

#toast-host {
  pointer-events: none;
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: min(420px, calc(100% - 24px));
}

.toast {
  background: rgba(24, 24, 36, 0.94);
  border: 1px solid #456;
  border-radius: 8px;
  color: #e8ecf2;
  font-size: 13px;
  padding: 8px 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease-out;
}

.toast.toast-ok {
  border-color: #3a7a4a;
  color: #cfe;
}

.toast.toast-warn {
  border-color: #8a6a30;
  color: #fed;
}

.toast.toast-error {
  border-color: #8a3a3a;
  color: #fcc;
}

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

.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
}

.shortcuts-table td {
  padding: 6px 4px;
  border-bottom: 1px solid #333;
  color: #bbb;
  vertical-align: middle;
}

.shortcuts-table td:first-child {
  width: 42%;
  color: #ddd;
  white-space: nowrap;
}

.shortcuts-table kbd,
.modal kbd {
  background: #12121c;
  border: 1px solid #555;
  border-radius: 4px;
  color: #cde;
  display: inline-block;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  margin: 0 1px;
  min-width: 1.4em;
  padding: 2px 6px;
  text-align: center;
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 220px minmax(0, 1fr) 180px;
  }
}

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
  }

  #panel-left,
  #panel-right {
    max-height: 28vh;
    overflow: auto;
    border: none;
  }

  #panel-left {
    border-bottom: 1px solid #2a2a38;
    order: 2;
  }

  #panel-main {
    order: 1;
    min-height: 40vh;
  }

  #panel-right {
    border-top: 1px solid #2a2a38;
    order: 3;
    flex-direction: row;
    max-height: none;
  }

  #panel-right .panel-section {
    flex: 1;
  }

  #panel-right .panel-tools {
    border-top: none;
    border-left: 1px solid #2a2a38;
  }

  .btn-text {
    display: none;
  }
}

@media (max-width: 640px) {
  .btn-cost {
    display: none;
  }

  #log-panel {
    width: 100%;
    max-height: 180px;
    border-radius: 0;
  }
}
