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

:root {
  --bg: #1a1b1e;
  --bg-card: #232529;
  --bg-overlay: rgba(0,0,0,0.6);
  --bg-paper: #f0e8d5;
  --text: #e4e0d8;
  --text-secondary: #9a9690;
  --text-dark: #2a2520;
  --accent: #c9a94e;
  --accent-dim: #8a7a3e;
  --border: #2e3035;
  --danger: #c44a4a;
  --success: #5a9e6f;
  --radius: 8px;
  --radius-sm: 4px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app { max-width: 1360px; margin: 0 auto; padding: 20px; }
.screen { display: none; }
.screen.active { display: block; }

#screen-loading { display: none; justify-content: center; align-items: center; min-height: 60vh; }
#screen-loading.active { display: flex; }
.loading-text { font-size: 1.2rem; color: var(--accent); }

/* ===== Title ===== */
.title-block { text-align: center; padding: 48px 0 24px; margin-bottom: 32px; }
.game-title { font-size: 2.4rem; letter-spacing: 4px; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.subtitle { margin-top: 8px; font-size: 0.95rem; color: var(--text-secondary); }
.screen-title { font-size: 1.6rem; color: var(--accent); text-align: center; margin-bottom: 24px; font-weight: 600; }

/* ===== Ivan Modal Backdrop ===== */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: var(--bg-overlay);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.active { display: flex; }
.modal-backdrop .modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; max-width: 420px; width: 90%;
}

/* ===== Character Select ===== */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.char-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
  transition: border-color 0.2s, transform 0.2s; cursor: default;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.char-card:hover { border-color: var(--accent); transform: scale(1.03); }
.char-header { display: flex; align-items: center; gap: 14px; }
.char-avatar { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; font-weight: 700; color: #fff; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
.avatar-wrapper { flex-shrink: 0; }
.avatar-img { border-radius: 50%; object-fit: cover; display: block; flex-shrink: 0; }
.avatar-fallback { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.char-name { font-size: 1.1rem; color: var(--accent); font-weight: 600; }
.char-title { font-size: 0.82rem; color: var(--text-secondary); }
.char-desc { font-size: 0.88rem; color: var(--text); line-height: 1.5; }
.char-stats { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-secondary); padding-top: 10px; border-top: 1px solid var(--border); }
.char-stat-value { color: var(--accent); font-weight: 600; }

/* ===== Intro Screen ===== */
#screen-intro.active { display: flex; align-items: center; justify-content: center; min-height: 90vh; }
.intro-container { max-width: 620px; margin: 0 auto; }
.intro-text { font-size: 1.05rem; line-height: 1.8; color: var(--text); }
.intro-text p { margin-bottom: 1em; }
.intro-text ul { margin-bottom: 1em; padding-left: 24px; }
.intro-text li { margin-bottom: 0.3em; color: var(--accent); }
.intro-btn { display: block; margin: 32px auto 0; font-size: 1.1rem; padding: 14px 48px; }

/* ===== Buttons ===== */
.btn {
  border: none; padding: 10px 22px; font-size: 0.9rem; font-family: inherit;
  border-radius: var(--radius-sm); cursor: pointer; transition: background 0.2s, opacity 0.15s; font-weight: 500;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--bg); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #dbb956; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #3a3d44; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
.btn-play { margin-top: auto; }

/* ===== Modal ===== */
.modal-overlay { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; max-width: 480px; width: 100%; }
.modal-wide { max-width: 700px; }
.modal-title { font-size: 1.3rem; color: var(--accent); font-weight: 600; margin-bottom: 24px; text-align: center; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 6px; }
.form-input { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 0.95rem; font-family: inherit; }
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input-short { max-width: 300px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ===== Game Screen full-height ===== */
#screen-game.active {
  display: flex; flex-direction: column;
  height: calc(100vh - 40px);
}
#screen-game.active > .game-header { flex-shrink: 0; margin-bottom: 10px; }
#screen-game.active > .game-columns { flex: 1; min-height: 0; margin-bottom: 10px; }
#screen-game.active > .plan-bar { flex-shrink: 0; }

/* ===== Game Header ===== */
.game-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); flex-wrap: wrap; gap: 6px;
}
.header-item { font-size: 0.9rem; color: var(--text-secondary); position: relative; }
.header-item span { color: var(--accent); font-weight: 600; }

/* ===== Timeline Tooltip ===== */
.header-item#header-timeline { overflow: visible; }
.timeline-tooltip {
  display: none; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--bg-card); border: 1px solid var(--accent); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 0.78rem; color: var(--text-secondary);
  width: 300px; line-height: 1.5; margin-top: 8px; pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

/* ===== Columns ===== */
.game-columns { display: grid; grid-template-columns: 1.2fr 2fr 0.8fr; gap: 10px; }
@media (max-width: 1000px) { .game-columns { grid-template-columns: 1fr; } }
.column {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; overflow-y: auto;
}
.col-title { font-size: 0.95rem; color: var(--accent); font-weight: 600; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.slots-hint { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; }
.slots-hint span { color: var(--accent); font-weight: 600; }

/* ===== News Column - full height ===== */
.col-news { display: flex; flex-direction: column; min-height: 0; }
.col-news .news-list { flex: 1; overflow-y: auto; }

.news-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.news-item {
  padding: 12px 14px; background: var(--bg-paper); color: var(--text-dark);
  border-radius: var(--radius-sm); font-size: 0.85rem; line-height: 1.5; border-left: 3px solid var(--accent);
}

/* ===== Topics ===== */
.topics-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.slot-section-header {
  font-size: 0.78rem; color: var(--accent-dim); text-transform: uppercase;
  letter-spacing: 1px; padding: 8px 0 2px 4px; border-bottom: 1px solid var(--border);
  margin-top: 4px;
}
.slot-section-header:first-child { margin-top: 0; }
.topic-card {
  background: var(--bg); padding: 12px; border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--border);
}
.topic-card.taken { opacity: 0.35; }
.topic-title { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.topic-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4; }
.topic-meta { display: flex; align-items: center; gap: 8px; }
.slot-badge { display: inline-block; background: var(--accent-dim); color: #fff; padding: 2px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.btn-take { align-self: flex-end; padding: 5px 16px; font-size: 0.8rem; background: var(--accent); color: var(--bg); border: none; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; font-weight: 500; }
.btn-take:hover:not(:disabled) { background: #dbb956; }
.btn-take:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== Rating ===== */
.rating-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.rating-table th { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); color: var(--accent); font-weight: 600; }
.rating-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.rating-table tr.player-row td { color: var(--accent); font-weight: 600; }

/* ===== Plan Bar ===== */
.plan-bar { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.plan-left { flex: 1; min-width: 200px; }
.plan-title { font-size: 0.9rem; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.plan-slots { display: flex; gap: 6px; margin-bottom: 8px; }
.slot-placeholder, .slot-filled { width: 68px; height: 28px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 0.7rem; }
.slot-placeholder { border: 1px dashed var(--border); color: var(--text-secondary); }
.slot-filled { border: 1px solid var(--accent); background: rgba(201,169,78,0.12); color: var(--accent); font-weight: 600; }
.plan-topics-list { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-topic-item { background: var(--bg); border: 1px solid var(--border); padding: 5px 10px; border-radius: var(--radius-sm); font-size: 0.82rem; display: flex; align-items: center; gap: 6px; }
.btn-remove-topic { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.9rem; }
.plan-actions { display: flex; gap: 8px; align-items: flex-end; }

/* ===== Report ===== */
.report-content { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.report-block { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.report-block h3 { color: var(--accent); margin-bottom: 12px; font-size: 1rem; font-weight: 600; }
.report-theme { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.report-theme-item { background: var(--bg); border: 1px solid var(--border); padding: 10px 14px; border-radius: var(--radius-sm); flex: 1; min-width: 200px; border-left: 3px solid var(--text-secondary); }
.report-theme-item.hit { border-left-color: var(--success); }
.report-theme-item.miss { border-left-color: var(--danger); }
.report-theme-item.ok { border-left-color: var(--warning); }
.report-theme-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.report-theme-score { font-size: 0.82rem; color: var(--text-secondary); }
.report-theme-verdict { margin-top: 4px; font-size: 0.82rem; font-style: italic; color: var(--text-secondary); }
.report-sub-gain { font-size: 1.1rem; font-weight: 700; color: var(--success); }
.report-npc-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.report-npc-item:last-child { border-bottom: none; }
.report-npc-name { font-weight: 600; color: var(--accent); }
.report-npc-gain { color: var(--success); font-size: 0.9rem; }
.report-npc-reason { font-size: 0.82rem; color: var(--text-secondary); font-style: italic; margin-top: 2px; }

/* ===== Final ===== */
.ending-image { text-align: center; font-size: 4rem; padding: 24px 0 8px; line-height: 1.2; }
.final-content { max-width: 600px; margin: 0 auto 24px; }
.final-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.final-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--accent); color: var(--accent); font-size: 0.95rem; }
.final-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.final-table tr.winner td { color: var(--accent); font-weight: 600; background: rgba(201,169,78,0.06); }
.final-winner { text-align: center; font-size: 1.2rem; color: var(--accent); margin-bottom: 16px; padding: 16px; border: 1px solid var(--accent); border-radius: var(--radius); font-weight: 600; }
.final-password { text-align: center; font-size: 0.95rem; color: var(--text-secondary); font-style: italic; padding: 12px; background: var(--bg-card); border-radius: var(--radius); max-width: 600px; margin: 0 auto; }
.final-epilogue { font-size: 0.9rem; font-style: italic; color: var(--text-secondary); text-align: center; line-height: 1.6; padding: 16px; background: var(--bg-card); border-radius: var(--radius); white-space: pre-line; }
#btn-next-month, #btn-new-game { display: block; margin: 0 auto; font-size: 1rem; padding: 12px 32px; }

/* ===== Archive ===== */
.archive-login { text-align: center; padding: 20px 0; }
.archive-hint { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 16px; }
.archive-login > div { justify-content: center; }
.archive-error { font-size: 0.85rem; color: var(--danger); margin-top: 12px; }
.archive-content { max-height: 50vh; overflow-y: auto; }
.archive-month { margin-bottom: 20px; }
.archive-month-title { font-size: 0.95rem; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.archive-month ul { list-style: none; display: flex; flex-direction: column; gap: 4px; padding-left: 12px; }
.archive-month li { font-size: 0.85rem; color: var(--text-secondary); }

/* ===== Scrollbar ===== */
.column::-webkit-scrollbar, .news-list::-webkit-scrollbar { width: 5px; }
.column::-webkit-scrollbar-track, .news-list::-webkit-scrollbar-track { background: transparent; }
.column::-webkit-scrollbar-thumb, .news-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Avatar ===== */
.avatar-wrapper {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.avatar-img {
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #app { padding: 12px; }
  #screen-game.active { height: calc(100vh - 24px); }
  .game-title { font-size: 1.5rem; letter-spacing: 2px; }
  .char-grid { grid-template-columns: 1fr; }
  .plan-bar { flex-direction: column; }
  .plan-actions { width: 100%; }
  .plan-actions .btn { flex: 1; }
  .modal { margin: 0 12px; }
  .intro-text { font-size: 0.95rem; }
}
@media (max-width: 1000px) and (min-width: 769px) {
  .game-columns { grid-template-columns: 1fr 1fr; }
  .col-rating { order: -1; }
}
