:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --card-bg: #ffffff;
  --border: #d3d6da;
  --text: #1c1c1e;
  --text-dim: #5f6368;
  --green: #538d4e;
  --yellow: #b59f3b;
  --red: #a13a3a;
  --accent: #538d4e;
  --gold: #c9a227;
  --silver: #9aa0a6;
  --bronze: #a1662f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.logo {
  font-size: 1.3rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text);
}

.logo span {
  color: var(--green);
}

nav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
}

nav a {
  color: var(--text-dim);
  text-decoration: none;
}

nav a:hover {
  color: var(--text);
}

.nav-user {
  color: var(--green);
  font-weight: bold;
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown summary {
  cursor: pointer;
  color: var(--text-dim);
  list-style: none;
}

.nav-dropdown summary::-webkit-details-marker,
.nav-dropdown summary::marker {
  display: none;
  content: "";
}

.nav-dropdown summary:hover,
.nav-dropdown[open] summary {
  color: var(--text);
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.nav-dropdown-menu a {
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
}

.nav-dropdown-menu a:hover {
  background: var(--bg);
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.field-row {
  margin-bottom: 16px;
}

.field-row label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
textarea {
  width: 100%;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

select {
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.submit-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.error-msg {
  color: var(--red);
  background: rgba(161, 58, 58, 0.15);
  border: 1px solid var(--red);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.alert-success {
  color: var(--green);
  background: rgba(83, 141, 78, 0.15);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.auth-switch {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 16px 0 0;
}

.auth-switch a {
  color: var(--green);
}

.today-label {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: -8px 0 16px;
}

.last-result h3 {
  color: var(--green);
}

.score-final {
  font-size: 2rem;
  font-weight: bold;
  text-align: center;
  color: var(--green);
  margin: 12px 0;
}

.score-breakdown {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: center;
}

.score-breakdown div {
  flex: 1;
  background: var(--bg);
  border-radius: 4px;
  padding: 8px 4px;
}

.score-breakdown span {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.help {
  color: var(--text-dim);
}

.help summary {
  cursor: pointer;
  color: var(--text);
  font-weight: bold;
  font-size: 0.95rem;
}

.help pre {
  background: var(--bg);
  border-radius: 4px;
  padding: 10px;
  font-size: 0.85rem;
  overflow-x: auto;
  margin: 10px 0;
}

.help p {
  font-size: 0.85rem;
  line-height: 1.5;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 0.9rem;
}

.history-item .badge {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  background: var(--green);
  color: #fff;
  flex-shrink: 0;
}

.history-item .badge.fail {
  background: var(--red);
}

.history-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.history-puzzle {
  font-weight: bold;
}

.history-item .date {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.history-score {
  font-weight: bold;
  color: var(--green);
  white-space: nowrap;
}

.history-score small {
  color: var(--text-dim);
  font-weight: normal;
  font-size: 0.7rem;
}

.empty-msg {
  color: var(--text-dim);
  text-align: center;
  font-size: 0.9rem;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

table.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.leaderboard th,
table.leaderboard td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.leaderboard th {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.leaderboard tbody tr:first-child td {
  color: var(--green);
}

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  padding-top: 12px;
  flex-wrap: wrap;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 130px;
}

.podium-medal {
  font-size: 1.8rem;
}

.podium-name {
  font-weight: bold;
  margin-top: 4px;
  text-align: center;
  word-break: break-word;
}

.podium-score {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.podium-bar {
  width: 100%;
  border-radius: 6px 6px 0 0;
}

.podium-1 .podium-bar {
  height: 110px;
  background: var(--gold);
}

.podium-2 .podium-bar {
  height: 75px;
  background: var(--silver);
}

.podium-3 .podium-bar {
  height: 50px;
  background: var(--bronze);
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 48px;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.bar-label {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  height: 18px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
}

.bar-fill-winrate {
  background: var(--accent);
}

.bar-value {
  text-align: right;
  font-weight: bold;
}

.inline-form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.inline-form .field-row {
  margin-bottom: 0;
  min-width: 180px;
}

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 4px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  opacity: 0.88;
}

.btn-secondary {
  background: var(--text-dim);
}

.btn-danger {
  background: var(--red);
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.admin-table th,
table.admin-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.admin-table thead th {
  background: var(--bg);
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid var(--border);
}

table.admin-table tbody tr:hover {
  background: rgba(83, 141, 78, 0.05);
}

select.role-select {
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: bold;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  cursor: pointer;
}

select.role-select-admin {
  border-color: var(--green);
  color: var(--green);
  background: rgba(83, 141, 78, 0.1);
}

select.role-select-user {
  border-color: var(--border);
  color: var(--text-dim);
  background: var(--bg);
}

.history-entries {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.history-entry-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.history-entry-score {
  font-weight: bold;
  color: var(--green);
}

.history-entry-date {
  color: var(--text-dim);
  margin-left: auto;
}

.raw-paste {
  background: var(--bg);
  border-radius: 4px;
  padding: 10px;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-x: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.solution-word {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  font-size: 2rem;
  font-weight: bold;
  letter-spacing: 0.3em;
  color: var(--green);
}

.history-entry-solution {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.history-entry-solution strong {
  color: var(--green);
  letter-spacing: 0.05em;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.month-nav a {
  color: var(--green);
  font-size: 0.9rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-weekday {
  text-align: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  padding-bottom: 6px;
}

.calendar-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

.calendar-count {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.calendar-cell-ok .calendar-count {
  color: var(--green);
  font-weight: bold;
}

.calendar-cell-missing .calendar-count {
  color: var(--red);
}

.calendar-cell-blank {
  border: none;
}

.calendar-cell-ok {
  background: rgba(83, 141, 78, 0.1);
  border-color: var(--green);
}

.calendar-cell-missing {
  background: rgba(161, 58, 58, 0.08);
  border-color: var(--red);
}

.calendar-cell-future {
  background: var(--bg);
  color: var(--text-dim);
}

.calendar-day-num {
  font-weight: bold;
}

.sync-form {
  margin-top: 16px;
}

.day-dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 90%;
  max-width: 420px;
  background: var(--card-bg);
  color: var(--text);
}

.day-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.day-dialog h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.day-dialog h3:not(:first-child) {
  margin-top: 20px;
}

.solution-word-small {
  padding: 14px;
  font-size: 1.3rem;
}

.dialog-close-form {
  margin-top: 20px;
  text-align: right;
}
