* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #1a1a2e; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; user-select: none; }
canvas { display: block; }

/* Resource Bar */
#resourceBar {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 16px; background: rgba(10,10,30,0.88); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 8px 20px; z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.resource { display: flex; align-items: center; gap: 6px; color: #e0e0e0; font-size: 14px; font-weight: 500; }
.resource .icon { width: 22px; height: 22px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.resource .rate { font-size: 10px; color: #4ecdc4; margin-left: 1px; }
.res-wood .icon { background: #5D4037; } .res-water .icon { background: #1565C0; }
.res-gold .icon { background: #F57F17; } .res-food .icon { background: #E65100; }
.res-pop .icon { background: #7B1FA2; }

/* Build Menu */
#buildMenu {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(10,10,30,0.88); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 14px; padding: 8px 12px 10px; z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4); display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.tab-bar { display: flex; gap: 4px; }
.build-tab {
  padding: 4px 12px; border-radius: 6px; background: rgba(255,255,255,0.05);
  color: #999; font-size: 11px; cursor: pointer; border: 1px solid transparent; transition: all 0.2s;
}
.build-tab:hover { color: #ccc; background: rgba(255,255,255,0.1); }
.build-tab.active { color: #4ecdc4; border-color: #4ecdc4; background: rgba(78,205,196,0.1); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.build-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 10px; border-radius: 8px; border: 2px solid transparent;
  background: rgba(255,255,255,0.04); color: #bbb; cursor: pointer;
  transition: all 0.2s; min-width: 70px; font-size: 11px;
}
.build-btn:hover { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.15); }
.build-btn.selected { background: rgba(78,205,196,0.15); border-color: #4ecdc4; color: #fff; }
.build-btn.disabled { opacity: 0.35; cursor: not-allowed; }
.build-btn .b-icon { font-size: 22px; line-height: 1; }
.build-btn .b-name { font-size: 10px; font-weight: 600; }
.build-btn .b-cost { font-size: 9px; color: #888; }

/* Tooltip */
#tooltip {
  position: fixed; display: none; background: rgba(10,10,30,0.92); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; padding: 10px 14px;
  color: #ddd; font-size: 12px; z-index: 20; pointer-events: none; max-width: 240px;
}
.tt-title { font-weight: 700; font-size: 13px; color: #fff; margin-bottom: 3px; }
.tt-desc { color: #aaa; font-size: 11px; margin-bottom: 5px; }
.tt-stats { font-size: 11px; line-height: 1.5; }

/* Notifications */
#notifications { position: fixed; top: 60px; right: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 15; }
.notification {
  background: rgba(10,10,30,0.85); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 7px 12px; color: #e0e0e0; font-size: 12px;
  animation: notifIn 0.3s ease, notifOut 0.4s ease 2.4s forwards;
}
.notification.error { border-color: #e74c3c; color: #ff6b6b; }
.notification.success { border-color: #4ecdc4; color: #4ecdc4; }
.notification.disaster { border-color: #FF9800; color: #FFB74D; }
@keyframes notifIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes notifOut { from { opacity:1; } to { opacity:0; transform:translateY(-10px); } }

/* Delete hint */
#deleteHint {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(231,76,60,0.85); border: 1px solid #e74c3c; border-radius: 8px;
  padding: 6px 14px; color: #fff; font-size: 12px; z-index: 15; display: none;
}

/* Starvation warning */
#starvationWarn {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(255,87,34,0.9); border: 1px solid #FF5722; border-radius: 8px;
  padding: 6px 14px; color: #fff; font-size: 12px; z-index: 15; display: none;
}

/* Corner buttons */
.corner-btn {
  position: fixed; z-index: 12; width: 36px; height: 36px; border-radius: 10px;
  background: rgba(10,10,30,0.85); border: 1px solid rgba(255,255,255,0.1);
  color: #ccc; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.corner-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
#musicBtn { top: 14px; right: 16px; }
#rulebookBtn { top: 14px; right: 58px; }

/* Help */
#helpOverlay {
  position: fixed; bottom: 80px; right: 14px; background: rgba(10,10,30,0.8);
  border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 8px 12px;
  color: #777; font-size: 10px; z-index: 10; line-height: 1.7;
}
#helpOverlay kbd {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 3px; padding: 0 4px; font-size: 9px; color: #aaa;
}

/* Rulebook */
#rulebook {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,0.6);
}
.rulebook-panel {
  background: rgba(15,15,40,0.95); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 16px;
  padding: 28px 32px; max-width: 620px; width: 90%; max-height: 80vh;
  overflow-y: auto; color: #ccc; position: relative;
}
.rulebook-panel h2 { color: #fff; font-size: 20px; margin-bottom: 16px; text-align: center; }
.rulebook-panel h3 { color: #4ecdc4; font-size: 14px; margin: 14px 0 6px; }
.rulebook-panel p { font-size: 12px; line-height: 1.6; margin-bottom: 8px; color: #aaa; }
.rulebook-panel .section { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.rulebook-close {
  position: absolute; top: 12px; right: 16px; background: none; border: none;
  color: #888; font-size: 20px; cursor: pointer;
}
.rulebook-close:hover { color: #fff; }
.rulebook-panel::-webkit-scrollbar { width: 6px; }
.rulebook-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* Simulation banner */
#simBanner {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%);
  background: rgba(78,205,196,0.9); border: 1px solid #4ecdc4; border-radius: 8px;
  padding: 8px 18px; color: #1a1a2e; font-size: 13px; font-weight: 600;
  z-index: 16; text-align: center; pointer-events: none;
  animation: bannerFade 8s ease forwards;
  box-shadow: 0 4px 16px rgba(78,205,196,0.3);
}
#simBanner kbd {
  background: rgba(0,0,0,0.15); border: 1px solid rgba(0,0,0,0.2);
  border-radius: 3px; padding: 1px 5px; font-size: 12px;
}
@keyframes bannerFade {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  8% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

/* Save/Load/Email/AI/LLM corner buttons */
#saveBtn { top: 14px; right: 100px; }
#loadBtn { top: 14px; right: 142px; }
#emailBtn { top: 14px; right: 184px; }
#autoSimToggle {
  top: 14px; right: 226px; width: auto; padding: 0 12px;
  font-size: 12px; letter-spacing: 0.5px; transition: all 0.3s;
}
#llmToggle {
  top: 14px; right: 310px; width: auto; padding: 0 12px;
  font-size: 12px; letter-spacing: 0.5px; transition: all 0.3s;
}
#llmToggle.active {
  background: rgba(187,134,252,0.25); border-color: #BB86FC;
  color: #BB86FC; box-shadow: 0 0 12px rgba(187,134,252,0.3);
  animation: llmPulse 2s ease-in-out infinite;
}
@keyframes llmPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(187,134,252,0.2); }
  50% { box-shadow: 0 0 16px rgba(187,134,252,0.5); }
}
#autoSimToggle.active {
  background: rgba(78,205,196,0.25); border-color: #4ecdc4;
  color: #4ecdc4; box-shadow: 0 0 12px rgba(78,205,196,0.3);
  animation: aiPulse 2s ease-in-out infinite;
}
@keyframes aiPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(78,205,196,0.2); }
  50% { box-shadow: 0 0 16px rgba(78,205,196,0.5); }
}

/* Auto-Simulation Panel */
#autoSimPanel {
  position: fixed; top: 56px; left: 14px; width: 280px;
  background: rgba(10,10,30,0.92); backdrop-filter: blur(12px);
  border: 1px solid rgba(78,205,196,0.2); border-radius: 12px;
  padding: 12px; z-index: 12; max-height: calc(100vh - 120px);
  overflow-y: auto; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#autoSimPanel::-webkit-scrollbar { width: 4px; }
#autoSimPanel::-webkit-scrollbar-thumb { background: rgba(78,205,196,0.2); border-radius: 2px; }

.as-header {
  color: #4ecdc4; font-size: 14px; font-weight: 700; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid rgba(78,205,196,0.2);
}
.as-header-sub {
  color: #4ecdc4; font-size: 11px; font-weight: 600; margin: 8px 0 4px;
  text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.8;
}
.as-section { margin-bottom: 4px; }

.as-stat {
  display: inline-block; font-size: 11px; color: #aaa; margin-right: 10px;
}
.as-stat strong { color: #e0e0e0; }

.as-plan-item {
  font-size: 11px; color: #ccc; padding: 3px 6px; margin: 2px 0;
  background: rgba(255,255,255,0.04); border-radius: 4px;
  border-left: 2px solid #4ecdc4;
}
.as-plan-item.idle { border-left-color: #666; color: #888; }
.as-plan-icon { margin-right: 4px; }

.as-beaver-list { max-height: 180px; overflow-y: auto; }
.as-beaver-list::-webkit-scrollbar { width: 3px; }
.as-beaver-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.as-beaver {
  font-size: 10px; color: #bbb; padding: 2px 4px; margin: 1px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  line-height: 1.5;
}
.as-beaver strong { color: #e0e0e0; font-size: 10px; }
.as-thought {
  color: #4ecdc4; font-style: italic; font-size: 9px; display: block;
  margin-left: 18px; opacity: 0.85;
}

.as-log { max-height: 120px; overflow-y: auto; }
.as-log::-webkit-scrollbar { width: 3px; }
.as-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.as-log-entry {
  font-size: 10px; color: #888; padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.02);
}
.as-log-time {
  color: #666; font-size: 9px; margin-right: 6px;
  font-weight: 600;
}

/* Save/Load Dialog */
#saveLoadDialog {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
}
.dialog-panel {
  background: rgba(15,15,40,0.95); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 16px;
  padding: 28px 32px; max-width: 420px; width: 90%;
  color: #ccc; position: relative;
}
.dialog-panel h2 {
  color: #fff; font-size: 20px; margin-bottom: 16px; text-align: center;
}
.dialog-buttons {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;
}
.dialog-btn {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 10px 16px; color: #ddd; font-size: 13px;
  cursor: pointer; transition: all 0.2s; text-align: left;
}
.dialog-btn:hover {
  background: rgba(78,205,196,0.15); border-color: #4ecdc4; color: #fff;
}
#importArea { margin-top: 10px; }
#importText {
  width: 100%; height: 80px; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  color: #ccc; font-size: 11px; padding: 8px; resize: vertical;
  font-family: monospace; margin-bottom: 8px;
}
#saveInfo {
  font-size: 11px; color: #888; text-align: center; margin-top: 8px;
}

/* LLM Chat Log */
.llm-log { max-height: 200px; }
.llm-chat-entry {
  font-size: 10px; color: #aaa; padding: 3px 4px; margin: 1px 0;
  border-left: 2px solid #555; padding-left: 8px;
  line-height: 1.4;
}
.llm-role-assistant { border-left-color: #BB86FC; color: #d4b8ff; }
.llm-role-plan { border-left-color: #FFD54F; color: #ffe082; font-size: 10px; }
.llm-role-quote { border-left-color: #FF9800; color: #FFB74D; font-style: italic; font-size: 11px; padding: 4px 8px; background: rgba(255,152,0,0.08); }
.llm-role-system { border-left-color: #4ecdc4; color: #999; }
.llm-role-state { border-left-color: #555; color: #666; font-size: 9px; }
.llm-role-error { border-left-color: #ff6b6b; color: #ff6b6b; }

/* LLM Settings Dialog */
#llmSettingsDialog {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
}
.llm-provider-select {
  display: flex; gap: 16px; margin: 12px 0;
}
.llm-radio {
  font-size: 13px; color: #ccc; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.llm-radio input { accent-color: #BB86FC; }
.llm-key-section { margin: 12px 0; }
.llm-label { font-size: 12px; color: #aaa; display: block; margin-bottom: 6px; }
.llm-input {
  width: 100%; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 6px;
  color: #ddd; font-size: 13px; padding: 8px 12px;
  font-family: monospace; margin-bottom: 8px;
}
.llm-input:focus { outline: none; border-color: #BB86FC; }
.llm-key-buttons { display: flex; gap: 8px; }
.llm-status { font-size: 12px; margin: 8px 0; }
.llm-info {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.llm-info p {
  font-size: 11px; color: #777; margin: 4px 0; line-height: 1.4;
}
.llm-info kbd {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 3px; padding: 0 4px; font-size: 10px; color: #aaa;
}
