:root {
  --bg: #121213;
  --surface: #1a1a1b;
  --border: #3a3a3c;
  --text: #ffffff;
  --text-muted: #818384;
  --green: #538d4e;
  --yellow: #b59f3b;
  --red: #8b1a1a;
  --gray: #3a3a3c;
  --input-bg: #252527;
  --arrow-up: #4a9eff;
  --arrow-down: #ff7b4a;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  max-width: 900px;
  padding: 24px 16px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 4px;
  color: #e3e3e3;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 0.9rem;
}

main {
  width: 100%;
  max-width: 960px;
  padding: 0 16px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Search */
#search-container {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 600px;
}

#input-wrapper {
  position: relative;
  flex: 1;
}

#search-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus {
  border-color: #818384;
}

#autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

#autocomplete-list.hidden {
  display: none;
}

#autocomplete-list li {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

#autocomplete-list li:last-child {
  border-bottom: none;
}

#autocomplete-list li:hover,
#autocomplete-list li.active {
  background: var(--border);
}

#autocomplete-list li .code {
  font-weight: 700;
  font-size: 0.85rem;
  color: #aaa;
}

#autocomplete-list li .name {
  font-size: 0.95rem;
}

#guess-btn {
  padding: 12px 24px;
  background: #538d4e;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

#guess-btn:hover:not(:disabled) {
  background: #6aad65;
}

#guess-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Message */
#message-area {
  min-height: 28px;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

#message-area.error {
  color: #ff6b6b;
}

/* Guesses table */
#guesses-container {
  width: 100%;
  overflow-x: auto;
}

#guesses-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
  min-width: 720px;
}

#guesses-table thead th {
  padding: 6px 10px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

#guesses-table thead th:first-child,
#guesses-table thead th:nth-child(2) {
  text-align: left;
}

#guesses-table tbody tr {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#guesses-table tbody td {
  padding: 10px 10px;
  background: var(--surface);
  font-size: 0.9rem;
  text-align: center;
  vertical-align: middle;
}

#guesses-table tbody td:first-child {
  border-radius: 8px 0 0 8px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 1px;
  text-align: left;
  padding-left: 14px;
  min-width: 80px;
}

#guesses-table tbody td:nth-child(2) {
  text-align: left;
  font-size: 0.85rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#guesses-table tbody td:last-child {
  border-radius: 0 8px 8px 0;
}

/* Cell states */
.cell-green  { background: var(--green)  !important; color: white; font-weight: 700; }
.cell-yellow { background: var(--yellow) !important; color: white; font-weight: 700; }
.cell-red    { background: var(--red)    !important; color: #ffbbbb; font-weight: 700; }

.cell-up   { background: #1a3a5c !important; color: var(--arrow-up);  font-weight: 700; font-size: 1.3rem; }
.cell-down { background: #3a1a0a !important; color: var(--arrow-down); font-weight: 700; font-size: 1.3rem; }

/* Win modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content h2 {
  font-size: 1.6rem;
}

.modal-content p {
  color: var(--text-muted);
  line-height: 1.6;
}

#modal-close {
  margin-top: 8px;
  padding: 10px 24px;
  background: var(--green);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#modal-close:hover {
  background: #6aad65;
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.legend-dot.green  { background: var(--green);  }
.legend-dot.yellow { background: var(--yellow); }
.legend-dot.red    { background: var(--red);    }
.legend-dot.up     { background: #1a3a5c; }
.legend-dot.down   { background: #3a1a0a; }

/* Guessed indicator */
.already-guessed {
  opacity: 0.5;
  pointer-events: none;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
