/* CowSimulator - Shared Styles */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --panel: #16213e;
  --panel2: #0f3460;
  --accent: #f0c040;
  --accent2: #e94560;
  --text: #eee;
  --muted: #888;
  --border: #334;
  --cell-size: 48px;
  --grid-gap: 2px;
}

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 200px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  gap: 0.5rem;
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-align: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.sidebar a.sidebar-title { text-decoration: none; }

.tool-btn {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.88rem;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}
.tool-btn:hover { background: var(--panel2); border-color: var(--accent); color: var(--accent); }
.tool-btn.active { background: var(--accent); color: #1a1a2e; font-weight: 700; border-color: var(--accent); }
.tool-btn .icon { font-size: 1rem; flex-shrink: 0; }

.sidebar-sep { border: none; border-top: 1px solid var(--border); margin: 0.25rem 0; }

/* ── Main area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  min-height: 48px;
}
.top-bar .info-chip {
  background: var(--panel2);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 700;
}

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 2rem;
}

/* ── Grid ── */
.grid-wrapper {
  position: relative;
  user-select: none;
}
.grid-table {
  border-collapse: collapse;
  border: 2px solid var(--panel2);
}
.grid-table td {
  width: var(--cell-size);
  height: var(--cell-size);
  min-width: var(--cell-size);
  min-height: var(--cell-size);
  border: 1px solid #2a2a4a;
  position: relative;
  cursor: pointer;
  transition: filter 0.1s;
  overflow: hidden;
}
.grid-table td:hover { filter: brightness(1.3); }
.grid-table td .cell-img {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; pointer-events: none; z-index: 2;
}
.grid-table td .cell-mark {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; pointer-events: none; z-index: 3;
}

/* color palette used for cell backgrounds */
.c0  { background: #2a2a4a; } /* empty */
.c1  { background: #c2658b; }
.c2  { background: #acd994; }
.c3  { background: #ab6d45; }
.c4  { background: #68bce6; }
.c5  { background: #ffa0ec; }
.c6  { background: #e2ba45; }
.c7  { background: #6082b5; }
.c8  { background: #9178d0; }
.c9  { background: #47b3b0; }
.c10 { background: #ffa96c; }
.c11 { background: #a7bed9; }
.c12 { background: #ff5722; }
.c13 { background: #e6a8c0; }
.c14 { background: #9c27b0; }
.c15 { background: #ffeb3b; }

/* ── Color Picker Panel ── */
.color-picker-panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  z-index: 100;
  box-shadow: 0 8px 32px #0008;
  min-width: 180px;
  cursor: move;
}
.color-picker-panel .cp-title {
  font-size: 0.8rem; color: var(--muted); margin-bottom: 0.5rem; text-align: center;
}
.color-swatches {
  display: grid; grid-template-columns: repeat(4, 32px); gap: 4px;
}
.color-swatch {
  width: 32px; height: 32px; border-radius: 4px; cursor: pointer;
  border: 2px solid transparent; transition: transform 0.1s, border-color 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: white; transform: scale(1.15); }
.color-swatch.empty { background: #2a2a4a; border: 2px dashed #555; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: #0008; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.5rem; min-width: 320px;
  box-shadow: 0 12px 40px #0009;
}
.modal h3 { color: var(--accent); margin-bottom: 1rem; font-size: 1.1rem; }
.modal label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.modal input[type=number], .modal input[type=text] {
  width: 100%; padding: 0.5rem 0.75rem; background: var(--bg);
  border: 1px solid var(--border); color: var(--text); border-radius: 6px;
  font-size: 0.95rem; margin-bottom: 0.75rem;
}
.modal-btns { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.btn { padding: 0.45rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.88rem; font-weight: 600; }
.btn-primary { background: var(--accent); color: #1a1a2e; }
.btn-secondary { background: var(--panel2); color: var(--text); }
.btn-danger { background: var(--accent2); color: #fff; }

/* ── Status messages ── */
.status-msg { font-size: 0.85rem; padding: 0.3rem 0.75rem; border-radius: 4px; }
.status-msg.ok { background: #1a3a2a; color: #4caf50; }
.status-msg.err { background: #3a1a1a; color: #e94560; }
.status-msg.info { background: #1a2a3a; color: #64b5f6; }

/* ── Simulator specific ── */
.remain-badge {
  font-size: 1rem; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--accent);
  color: var(--accent); padding: 0.25rem 0.75rem; border-radius: 20px;
}
.win-overlay {
  position: fixed; inset: 0; background: #000b; z-index: 300;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-size: 2rem; color: var(--accent); font-weight: 900;
}
.win-overlay .win-emoji { font-size: 5rem; animation: pop 0.5s ease; }
@keyframes pop { 0%{transform:scale(0)} 80%{transform:scale(1.2)} 100%{transform:scale(1)} }

/* ── highlight for marker mode ── */
.cell-candidate { outline: 2px solid #f0c04066; outline-offset: -2px; }
