:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #1f2d2b;
  --ink-soft: #55625f;
  --line: #dbe2e0;
  --accent: #0f6e56;
  --accent-ink: #ffffff;
  --danger: #a32d2d;
  --warn-bg: #faeeda;
  --warn-ink: #633806;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  line-height: 1.7;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.topbar nav a {
  margin-left: 18px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 14px;
}

.topbar nav a:hover { color: var(--accent); }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.wrap.narrow { max-width: 440px; }

h1 {
  font-size: 22px;
  margin: 0 0 20px;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
}
h2 {
  font-size: 17px;
  margin: 32px 0 12px;
  padding: 8px 14px;
  background: #eef4f2;
  color: var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
}
h3 {
  font-size: 15px;
  margin: 20px 0 10px;
  padding: 6px 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 6px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.grid-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--ink);
}
.tile:hover { border-color: var(--accent); }
.tile .tile-title { font-size: 17px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.tile .tile-desc { font-size: 13px; font-weight: 400; color: var(--ink-soft); line-height: 1.5; }

label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 14px 0 4px;
}

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

textarea { min-height: 140px; font-family: ui-monospace, monospace; font-size: 13px; }
textarea.textarea-large { min-height: 260px; font-size: 14px; }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { opacity: 0.9; }
button.secondary, .btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger, .btn.danger { background: var(--danger); }

.actions { margin-top: 20px; display: flex; gap: 10px; }

.msg-error {
  background: #fcebeb;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.msg-ok {
  background: #eaf3de;
  color: #27500a;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.badge.role-admin { background: #eeedfe; color: #26215c; }
.badge.mastered { background: #eaf3de; color: #27500a; }

.problem-box {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  font-size: 22px;
  text-align: center;
  margin-bottom: 20px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
}
.problem-box .problem-statement { line-height: 1.7; }

.mathjax-preview { font-size: 15px; line-height: 1.6; }

.timer {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.timer.low { color: var(--danger); }

.progress-line { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }

@keyframes pop-in {
  0%   { transform: scale(0.85); opacity: 0; }
  60%  { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); }
}
.pop-in { animation: pop-in 0.35s ease-out; }

.level-up-banner {
  background: linear-gradient(90deg, #fff4d6, #ffe9a8);
  border: 1px solid #f0c95c;
  color: #6b4e00;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  text-align: center;
}
