/* ── Theme tokens ────────────────────────────────────────── */
:root {
  --bg:             #e8e8e8;
  --bg-nav:         #2c3444;
  --bg-nav-hover:   #1a2030;
  --bg-surface:     #fff;
  --bg-header:      #f0f0f0;
  --bg-header-h:    #e4e4e4;
  --bg-btn:         #f5f5f5;
  --bg-btn-h:       #e8e8e8;
  --bg-table-th:    #f5f5f5;
  --bg-table-row-h: #f0f5ff;
  --bg-table-sub:   #fafafa;
  --bg-table-total: #f5f5f5;
  --bg-err:         #fdf0f0;
  --bg-ok:          #f0f8f0;
  --bg-input:       #fff;

  --text:           #333;
  --text-nav:       #d0d8e8;
  --text-meta:      #888;
  --text-link:      #1155cc;
  --text-err:       #c00;
  --text-ok:        #060;
  --text-note:      #9a6700;

  --border:         #ccc;
  --border-light:   #eee;
  --border-table:   #ddd;
  --border-err:     #e88;
  --border-ok:      #8c8;
  --border-input:   #bbb;
  --border-focus:   #38f;

  --heatmap-empty:  #dce0e6;
  --heatmap-bg-rgb: 220, 224, 230;

  --bg-pattern:
    linear-gradient(30deg,  rgba(0,0,0,.008) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,.008) 87.5%, rgba(0,0,0,.008)),
    linear-gradient(150deg, rgba(0,0,0,.008) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,.008) 87.5%, rgba(0,0,0,.008)),
    linear-gradient(30deg,  rgba(0,0,0,.008) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,.008) 87.5%, rgba(0,0,0,.008)),
    linear-gradient(150deg, rgba(0,0,0,.008) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,.008) 87.5%, rgba(0,0,0,.008)),
    linear-gradient(60deg,  rgba(0,0,0,.012) 25%, transparent 25.5%, transparent 75%, rgba(0,0,0,.012) 75%, rgba(0,0,0,.012)),
    linear-gradient(60deg,  rgba(0,0,0,.012) 25%, transparent 25.5%, transparent 75%, rgba(0,0,0,.012) 75%, rgba(0,0,0,.012));
}

[data-theme="dark"] {
  --bg:             #181b22;
  --bg-nav:         #1a1d28;
  --bg-nav-hover:   #111420;
  --bg-surface:     #23262f;
  --bg-header:      #1c1f2a;
  --bg-header-h:    #252836;
  --bg-btn:         #2a2d38;
  --bg-btn-h:       #32364a;
  --bg-table-th:    #1c1f2a;
  --bg-table-row-h: #2a2f42;
  --bg-table-sub:   #1e2030;
  --bg-table-total: #1c1f2a;
  --bg-err:         #3a1515;
  --bg-ok:          #152515;
  --bg-input:       #1e2130;

  --text:           #ccd0d8;
  --text-meta:      #7a8090;
  --text-link:      #5b9cf6;
  --text-err:       #f08080;
  --text-ok:        #80c880;
  --text-note:      #e3b341;

  --border:         #383c4a;
  --border-light:   #2e3140;
  --border-table:   #303448;
  --border-err:     #7a3030;
  --border-ok:      #307030;
  --border-input:   #404560;
  --border-focus:   #5b9cf6;

  --heatmap-empty:  #2a2d35;
  --heatmap-bg-rgb: 42, 45, 53;

  --bg-pattern:     none;
}

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

body {
  font-family: Arial, "Helvetica Neue", sans-serif;
  font-size: 13px;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-pattern);
  background-size: 40px 70px;
  background-position: 0 0, 0 0, 20px 35px, 20px 35px, 0 0, 20px 35px;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ─────────────────────────────── */
#nav {
  background: var(--bg-nav);
  display: flex;
  align-items: stretch;
  padding: 0 20px;
  gap: 2px;
}
#nav a {
  color: var(--text-nav);
  padding: 9px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
}
#nav a:hover, #nav a.active {
  background: var(--bg-nav-hover);
  color: #fff;
  text-decoration: none;
}
#nav .brand { color: #fff; font-weight: bold; font-size: 14px; }
#nav .spacer { flex: 1; }
#nav form { display: flex; align-items: center; }
#nav form button {
  background: none; border: none; color: var(--text-nav);
  padding: 9px 12px; cursor: pointer; font-size: 13px;
}
#nav form button:hover { color: #fff; }
#nav .theme-btn {
  background: none; border: none; color: var(--text-nav);
  padding: 9px 10px; cursor: pointer; font-size: 15px; line-height: 1;
  display: flex; align-items: center;
}
#nav .theme-btn:hover { color: #fff; }

/* ── Page ────────────────────────────── */
#page {
  max-width: 1140px;
  margin: 14px auto;
  padding: 0 14px;
}

/* ── Section box ─────────────────────── */
.box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.box-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  font-weight: bold;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.box-header:hover { background: var(--bg-header-h); }
.box-body { padding: 12px; }

/* ── Typography ──────────────────────── */
h1 { font-size: 20px; font-weight: bold; margin-bottom: 4px; }
h2 { font-size: 15px; font-weight: bold; margin-bottom: 8px; }
.meta { color: var(--text-meta); font-size: 11px; }
.error-msg {
  background: var(--bg-err); border: 1px solid var(--border-err);
  color: var(--text-err); padding: 6px 10px; font-size: 12px; margin-bottom: 8px;
}
.info-msg {
  background: var(--bg-ok); border: 1px solid var(--border-ok);
  color: var(--text-ok); padding: 6px 10px; font-size: 12px; margin-bottom: 8px;
}

/* ── Tables ──────────────────────────── */
table.t { border-collapse: collapse; width: 100%; }
.t th, .t td {
  border: 1px solid var(--border-table);
  padding: 4px 8px;
  white-space: nowrap;
}
.t th {
  background: var(--bg-table-th);
  font-size: 12px;
  text-align: center;
}
.t td { text-align: center; }
.t td.l { text-align: left; white-space: normal; }
.t tr:hover td { background: var(--bg-table-row-h); }
.t .sub td { background: var(--bg-table-sub); }
.t .sub:hover td { background: var(--bg-table-row-h); }
.t .total td { background: var(--bg-table-total); font-weight: bold; border-top: 2px solid var(--border); }
.t .total:hover td { background: var(--bg-table-total); }

.solved { color: #0a0; font-weight: bold; }
.r-up { color: #0a0; }
.r-dn { color: #c00; }

/* ── Solve-type badges ───────────────────── */
.st-live     { color: #0a0; font-weight: bold; }
.st-virtual  { color: #36c; font-weight: bold; }
.st-up       { color: #c70; font-weight: bold; font-size: 1.05em; }
.st-solo     { color: var(--text-meta); font-weight: bold; }
.wv          { color: var(--text-err); font-size: 10px; letter-spacing: .03em; }
.att         { color: var(--text-meta); font-size: 10px; margin-left: 1px; }

/* ── Sync dot ────────────────────────── */
.dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; vertical-align: middle; margin-left: 3px;
}
.dot-pending     { background: #aaa; }
.dot-syncing     { background: #38f; animation: pulse 1s infinite; }
.dot-done        { background: #0a0; }
.dot-error       { background: #c00; }
.dot-not_started { background: #f90; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Platform icon ───────────────────── */
.picon { width: 14px; height: 14px; vertical-align: middle; margin-right: 2px; }
/* A long title with no spaces must wrap inside the first column instead of stretching the whole matrix. */
.t td.item-cell { max-width: 340px; overflow-wrap: anywhere; }

/* Manual solve marks (CSES, Codeforces EDU) */
.solve-toggle {
  background: none; border: none; padding: 0 4px; font: inherit; line-height: 1;
  color: var(--text-meta); opacity: .45; cursor: pointer;
}
.solve-toggle:hover { opacity: 1; color: var(--text); }
.solve-toggle.on { color: #0a0; font-weight: bold; opacity: 1; }
.solved.manual { border-bottom: 1px dashed currentColor; }

/* ── Buttons ─────────────────────────── */
.btn, button.btn {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-btn);
  color: var(--text);
  text-decoration: none;
  line-height: 1.5;
}
.btn:hover, button.btn:hover { background: var(--bg-btn-h); text-decoration: none; }
.btn-green { background: #2a7a2a; color: #fff; border-color: #1a5a1a; }
.btn-green:hover { background: #1a5a1a; color: #fff; }
.btn-red { background: #b02020; color: #fff; border-color: #801010; }
.btn-red:hover { background: #901010; color: #fff; }

/* ── Forms ───────────────────────────── */
input[type=text], input[type=password], input[type=date],
textarea, select {
  border: 1px solid var(--border-input);
  padding: 3px 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 1px solid var(--border-focus); }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-col { display: flex; flex-direction: column; gap: 3px; }
.form-col label { font-size: 11px; font-weight: bold; color: var(--text-meta); }
.form-col input, .form-col textarea, .form-col select { min-width: 140px; }

/* ── Toggle arrow ────────────────────── */
.toggle {
  background: none; border: none; cursor: pointer;
  font-size: 10px; color: var(--text-meta); padding: 0 3px; vertical-align: middle;
}
.toggle:hover { color: var(--text); }

/* ── Login page ──────────────────────── */
#login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 80vh;
}
#login-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 28px 32px; width: 300px;
}
#login-box h1 { font-size: 18px; margin-bottom: 16px; text-align: center; }
#login-box .form-col { width: 100%; margin-bottom: 10px; }
#login-box input { width: 100%; }
#login-box .btn { width: 100%; text-align: center; padding: 5px; }

/* ── Group/assignment cards ──────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; margin-bottom: 10px; }
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 10px 12px; text-decoration: none; color: var(--text); display: block;
}
.card:hover { border-color: #888; text-decoration: none; background: var(--bg-header); }
.card h3 { font-size: 14px; margin-bottom: 3px; }

/* ── Member list ─────────────────────── */
.member-list { list-style: none; }
.member-list li {
  padding: 5px 0; border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.member-list li:last-child { border-bottom: none; }
.del-btn { background: none; border: none; color: var(--border); cursor: pointer; font-size: 16px; line-height: 1; }
.del-btn:hover { color: #c00; }

/* Hints */
.hint-btn {
  background: none; border: none; padding: 0 2px; margin-left: 4px; vertical-align: middle;
  line-height: 1; color: var(--text-meta); opacity: .4; cursor: pointer;
}
.hint-btn:hover { opacity: .7; }
.hint-btn svg { display: block; }
.hint-btn.has-hints { color: var(--text); opacity: 1; cursor: pointer; }
.hint-btn.has-hints:hover { color: var(--text-link); opacity: 1; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45); padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
  width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bg-header); border-bottom: 1px solid var(--border);
  font-weight: bold;
}
.modal-close { background: none; border: none; color: var(--text-meta); font-size: 20px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 12px 14px; overflow-y: auto; }
.modal-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.modal-sub { font-weight: normal; font-size: 12px; color: var(--text-meta); }

.hint-item { border: 1px solid var(--border); border-radius: 4px; margin-bottom: 8px; background: var(--bg-surface); overflow: hidden; }
.hint-row { display: flex; align-items: center; background: var(--bg-header); }
.hint-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; background: none; border: none; color: var(--text);
  font: inherit; font-weight: bold; text-align: left; cursor: pointer;
}
.hint-toggle:hover { background: var(--bg-header-h); }
.hint-chevron { display: inline-block; width: 10px; font-size: 11px; color: var(--text-meta); transition: transform .12s; }
.hint-item.open .hint-chevron { transform: rotate(90deg); }
.hint-label.solution { color: var(--text-err); }
.hint-label.note { color: var(--text-note); font-style: italic; }
.hint-note-author { margin-top: 6px; font-size: 11px; color: var(--text-meta); }
.hint-actions { display: flex; align-items: center; gap: 2px; padding-right: 8px; flex-shrink: 0; }
.hint-actions form { margin: 0; }
.hint-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  background: none; border: none; border-radius: 3px; color: var(--text-meta); cursor: pointer;
}
.hint-icon-btn:hover { background: var(--bg-btn-h); color: var(--text); }
.hint-icon-btn.danger:hover { color: var(--text-err); }
.hint-link { color: var(--text-link); text-decoration: underline; word-break: break-all; }
.hint-add { margin-top: 4px; }
.hint-add-row { display: flex; gap: 8px; }
.hint-add-row .hint-add-btn { flex: 1; }
.hint-add-btn {
  width: 100%; padding: 9px 12px; background: none; border: 1px dashed var(--border); border-radius: 4px;
  color: var(--text-meta); font: inherit; cursor: pointer;
}
.hint-add-btn:hover { border-color: var(--text-link); color: var(--text-link); }
.hint-add .hint-form { padding: 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-surface); }
.hint-content { padding: 10px 12px; border-top: 1px solid var(--border-light); }
.hint-text { white-space: pre-wrap; word-break: break-word; }
.hint-form textarea { width: 100%; margin-bottom: 8px; resize: vertical; }
.hint-form-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint-btn-row { display: flex; gap: 6px; }
.hint-check { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: normal; cursor: pointer; }
.hint-check input { width: auto; min-width: 0; margin: 0; }
.hint-time { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-meta); }
.hint-time input { width: 60px; min-width: 0; margin: 0; padding: 2px 5px; }

/* placeholder icon for links to sites we don't have a logo for */
.picon-unknown { display: inline-block; width: 14px; height: 14px; line-height: 14px; text-align: center; font-size: 11px; font-weight: 700; color: #777; border: 1px solid #bbb; border-radius: 3px; }

/* the AtCoder logo is dark on transparent; lighten it on the dark theme */
[data-theme="dark"] img[src$="/ac.png"] { filter: invert(1) brightness(1.15); }

/* profile page: judge chips, activity stats and legend */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: baseline; gap: 5px; padding: 3px 10px; font-size: 13px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; }
.chip a { color: inherit; font-weight: 600; }
.chip-codeforces strong { color: #1565C0; }
.chip-atcoder strong { color: #E09000; }
.chip-kilonova strong { color: #26a69a; }
.stats { display: inline-flex; gap: 14px; font-weight: normal; font-size: 12px; color: var(--text-meta); }
.stats b { color: var(--text); font-size: 14px; }
.legend { display: inline-flex; align-items: center; gap: 12px; font-size: 11px; font-weight: normal; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 3px; vertical-align: middle; }

.home-layout { display: flex; gap: 16px; align-items: flex-start; }
.home-main { flex: 1; min-width: 0; }
.home-side { width: 300px; flex-shrink: 0; }
@media (max-width: 800px) { .home-layout { flex-direction: column; } .home-side { width: 100%; } }
