/* === Base Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d1a;
  color: #c8c8d0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Game Container Grid === */
#game-container {
  display: grid;
  grid-template-areas:
    "status status inventory"
    "map map inventory"
    "hint hint inventory"
    "log log quests";
  grid-template-columns: 1fr 1fr 260px;
  grid-template-rows: 52px 1fr 40px 180px;
  aspect-ratio: 16 / 9;
  width: min(100vw, 177.78vh);
  height: min(100vh, 56.25vw);
  background: #1a1a2e;
  overflow: hidden;
}

/* === Status Bar === */
#status-bar {
  grid-area: status;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #12122a;
  border-bottom: 2px solid #2a2a4a;
  font-size: 15px;
  color: #c0c0d8;
  gap: 16px;
}

#status-bar span {
  white-space: nowrap;
}

#status-day {
  font-weight: bold;
  font-size: 17px;
  color: #ffffff;
  letter-spacing: 0.05em;
}

#status-phase {
  font-size: 15px;
  color: #8888bb;
}

#status-episode {
  font-size: 14px;
  color: #d4a832;
  font-style: italic;
  text-align: right;
}

.bar {
  display: inline-block;
  width: 120px;
  height: 14px;
  background: #1a1a30;
  border: 1px solid #3a3a5a;
  border-radius: 2px;
  vertical-align: middle;
  position: relative;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 1px;
}

.stamina-fill {
  background: #4a9e4a;
  width: 100%;
}

.hunger-fill {
  background: #c8a032;
  width: 100%;
}

/* === Quest Panel === */
#quest-panel {
  grid-area: quests;
  border-left: 2px solid #2a2a4a;
  border-top: 2px solid #2a2a4a;
  padding: 10px 14px;
  overflow-y: auto;
  background: #14142c;
}

#quest-panel h3 {
  color: #9999bb;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  border-bottom: 1px solid #2a2a4a;
  padding-bottom: 6px;
}

#quest-list {
  font-size: 13px;
  line-height: 1.6;
}

.quest-item {
  padding: 2px 0;
  color: #555577;
}

.quest-item.completed {
  color: #4a7a4a;
  text-decoration: line-through;
  text-decoration-color: #3a5a3a;
}

.quest-item.current {
  color: #d4a832;
  font-weight: bold;
}

.quest-item .quest-marker {
  display: inline-block;
  width: 16px;
  text-align: center;
}

.quest-item.current .quest-marker {
  color: #e8be3c;
}

.quest-item.completed .quest-marker {
  color: #4a9e4a;
}

/* === Map Area === */
#map-container {
  grid-area: map;
  display: flex;
  flex-direction: row;
  gap: 2px;
  overflow: hidden;
  background: #1a1a2e;
  padding: 8px;
  position: relative;
  min-width: 0;
  min-height: 0;
}

#ascii-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

#svg-panel {
  flex: 1;
  overflow: hidden;
  border-left: 2px solid #2a2a4a;
  min-width: 0;
}

#svg-map {
  width: 100%;
  height: 100%;
  display: block;
}

#map {
  margin: 0;
  padding: 0;
  line-height: 1.2;
  font-size: 14px;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.05em;
  white-space: pre;
  user-select: none;
  overflow: hidden;
}

/* === Map Tile Spans === */
#map span {
  cursor: default;
  display: inline-block;
  width: 1ch;
  text-align: center;
}

#map span:hover {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 1px;
}

/* === Map Tooltip === */
#map-tooltip {
  display: none;
  position: absolute;
  pointer-events: none;
  background: #0a0a18;
  border: 1px solid #4488cc;
  color: #d0d0e0;
  font-size: 13px;
  padding: 4px 10px;
  white-space: nowrap;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/* === Tile Colors === */
.water { color: #4488cc; }
.land { color: #8b7355; }
.sand { color: #d4c5a0; }
.tree { color: #4a8c3f; }
.wheat { color: #d4a832; }
.fire { color: #e8721c; }
.player { color: #ffffff; font-weight: bold; }
.npc { color: #e8d44d; }
.building { color: #a0a0b0; }
.item { color: #70c0a0; }
.path { color: #9b8b6b; }
.ruins { color: #6688aa; }
.grass { color: #5a7a4a; }
.bait { color: #d4a0ff; }

/* === Inventory Panel === */
#inventory-panel {
  grid-area: inventory;
  border-left: 2px solid #2a2a4a;
  padding: 14px 16px;
  overflow-y: auto;
  background: #14142c;
}

#inventory-panel h3 {
  color: #9999bb;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
  border-bottom: 1px solid #2a2a4a;
  padding-bottom: 8px;
}

#inventory-list {
  list-style: none;
  padding: 0;
}

#inventory-list li {
  padding: 4px 0;
  font-size: 15px;
  color: #70c0a0;
  line-height: 1.5;
}

#inventory-list li .item-qty {
  color: #a0a0b8;
  margin-left: 4px;
}

/* === Hint Bar === */
#hint-bar {
  grid-area: hint;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #101028;
  border-top: 2px solid #2a2a4a;
  font-size: 15px;
  color: #7799bb;
  gap: 20px;
  overflow: hidden;
  white-space: nowrap;
}

#hint-bar .hint-action {
  color: #5599dd;
  font-weight: bold;
}

#hint-bar .hint-food {
  color: #70c0a0;
}

/* === Log Panel === */
#log-panel {
  grid-area: log;
  border-top: 2px solid #2a2a4a;
  padding: 12px 16px;
  overflow-y: auto;
  background: #111126;
  max-height: 180px;
}

#log-content {
  font-size: 15px;
  color: #9999b0;
  line-height: 1.6;
}

#log-content .log-entry {
  padding: 2px 0;
}

#log-content .log-entry.important {
  color: #e8be3c;
  font-weight: bold;
}

#log-content .log-entry.system {
  color: #7799bb;
}

/* === Overlays === */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 20, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* === Title Screen === */
#title-content {
  text-align: center;
}

#title-art {
  color: #4488cc;
  font-size: 14px;
  line-height: 1.2;
  margin-bottom: 32px;
  text-shadow: 0 0 8px rgba(68, 136, 204, 0.3);
}

#title-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-item {
  font-size: 18px;
  padding: 8px 28px;
  color: #8888a8;
  cursor: pointer;
  transition: color 0.15s;
}

.menu-item:hover,
.menu-item.selected {
  color: #ffffff;
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
}

.menu-item.disabled {
  color: #444466;
  cursor: default;
  text-shadow: none;
}

#howto-info {
  color: #c0c0d0;
  font-size: 14px;
  line-height: 1.6;
  margin-top: 16px;
  text-align: left;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

#howto-info h2 {
  color: #4488cc;
  text-align: center;
  margin: 0 0 12px 0;
  font-size: 20px;
  text-shadow: 0 0 8px rgba(68, 136, 204, 0.3);
}

#howto-info p {
  margin: 4px 0;
}

#howto-info .howto-columns {
  display: flex;
  gap: 32px;
}

#howto-info .howto-columns > div {
  flex: 1;
}

#howto-info .item-char {
  display: inline-block;
  width: 18px;
  color: #4488cc;
  font-weight: bold;
  text-align: center;
}

.howto-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-top: 16px;
}

.howto-page-num {
  color: #666688;
  font-size: 14px;
}

.howto-prev,
.howto-next {
  font-size: 16px;
}

#howto-info > .menu-item[data-action="back"] {
  text-align: center;
  margin-top: 8px;
}

/* === Cutscene Overlay === */
#cutscene-overlay {
  background: rgba(0, 0, 0, 0.98);
  flex-direction: column;
}

#cutscene-video {
  max-width: 80%;
  max-height: 80%;
}

#cutscene-skip {
  position: absolute;
  bottom: 32px;
  right: 32px;
  color: #666688;
  font-size: 13px;
  animation: pulse 2s ease-in-out infinite;
}

/* === Dialogue Overlay === */
#dialogue-overlay {
  align-items: flex-end;
  padding-bottom: 40px;
  background: rgba(10, 10, 20, 0.6);
}

#dialogue-box {
  background: #12122a;
  border: 1px solid #3a3a6a;
  padding: 20px 24px;
  max-width: 640px;
  width: 90%;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: row;
  gap: 16px;
}

#dialogue-portrait {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid #3a3a6a;
  flex-shrink: 0;
  align-self: flex-start;
}

#dialogue-portrait.hidden {
  display: none;
}

#dialogue-content {
  flex: 1;
  min-width: 0;
}

#dialogue-speaker {
  color: #e8d44d;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 8px;
}

#dialogue-text {
  color: #c8c8d0;
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 12px;
}

#dialogue-choices {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#dialogue-choices .choice {
  color: #8888a8;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 15px;
  transition: color 0.15s;
}

#dialogue-choices .choice:hover,
#dialogue-choices .choice.selected {
  color: #ffffff;
  background: rgba(68, 136, 204, 0.1);
}

#dialogue-choices .choice::before {
  content: attr(data-key) ". ";
  color: #4488cc;
}

.dialogue-choice {
  color: #8888a8;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 15px;
  transition: color 0.15s;
}

.dialogue-choice:hover {
  color: #ffffff;
  background: rgba(68, 136, 204, 0.1);
}

.dialogue-continue {
  color: #555577;
  font-size: 13px;
  padding: 4px 8px;
  font-style: italic;
}

/* === Chunk Choice === */
.chunk-choice {
  padding: 10px 12px !important;
  border: 1px solid #2a2a4a;
  margin-bottom: 6px;
  border-radius: 4px;
  transition: border-color 0.15s, background 0.15s;
}

.chunk-choice:hover {
  border-color: #4488cc;
  background: rgba(68, 136, 204, 0.15) !important;
}

.chunk-choice strong {
  color: #e8d44d;
}

.chunk-desc {
  color: #8888a8;
  font-size: 13px;
}

/* === Flash Animation === */
@keyframes flash {
  0% { background: transparent; }
  50% { background: rgba(255, 255, 255, 0.15); }
  100% { background: transparent; }
}

.tile-flash {
  animation: flash 0.3s ease-out;
}

/* === Pulse Animation === */
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* === Scrollbar Styling === */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
  background: #3a3a5a;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4a4a6a;
}
