/* ----- Reset & base ----- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f1115;
  color: #e6e6e6;
  font-size: 14px;
  line-height: 1.5;
}
button { font-family: inherit; }
input { font-family: inherit; }

/* ----- Layout ----- */
#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

#sidebar {
  background: #161a22;
  border-right: 1px solid #262b36;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#main {
  display: grid;
  grid-template-rows: auto minmax(380px, 1.25fr) minmax(360px, 1.1fr) minmax(130px, 0.35fr);
  overflow-y: auto;
  overflow-x: hidden;
}

#main.editor-expanded {
  grid-template-rows: auto minmax(0, 1fr);
}

/* ----- Sidebar ----- */
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #262b36;
}
.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
  color: #fff;
  letter-spacing: -0.01em;
}
.sidebar-header .subtitle {
  font-size: 12px;
  color: #8a93a3;
  margin-top: 2px;
}
.user-panel {
  margin-top: 12px;
  padding: 10px;
  background: #111722;
  border: 1px solid #262b36;
  border-radius: 6px;
}
.user-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.user-avatar, .score-avatar, .profile-avatar {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1d4ed8;
  color: #fff;
  font-weight: 700;
}
.user-avatar, .score-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 11px;
}
.user-name {
  color: #e6e6e6;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.mini-btn, .mini-link {
  border: 1px solid #2a3140;
  background: #1c2230;
  color: #c5cbd6;
  border-radius: 4px;
  padding: 4px 7px;
  font-size: 11.5px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
}
.mini-btn:hover, .mini-link:hover { background: #232a3a; color: #fff; }
.mini-btn.hidden { display: none; }
.google-signin-slot.hidden { display: none; }
.google-signin-sidebar {
  max-width: 180px;
  overflow: hidden;
}
#search {
  margin-top: 12px;
  width: 100%;
  padding: 7px 10px;
  background: #0f1115;
  border: 1px solid #2a3140;
  border-radius: 6px;
  color: #e6e6e6;
  outline: none;
  font-size: 13px;
}
#search:focus { border-color: #3b82f6; }
.progress {
  margin-top: 10px;
  font-size: 12px;
  color: #8a93a3;
}

.question-list {
  overflow-y: auto;
  padding: 8px 0;
  flex: 1;
}
.pattern-group {
  margin-bottom: 4px;
}
.pattern-header {
  padding: 10px 16px 4px;
  color: #8a93a3;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.q-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  color: #c5cbd6;
  font-size: 13px;
  user-select: none;
}
.q-item:hover { background: #1c2230; }
.q-item.active {
  background: #1f2735;
  border-left-color: #3b82f6;
  color: #fff;
}
.q-item .q-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-status {
  width: 14px; height: 14px; border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; line-height: 1;
}
.q-status.solved { background: #1f3b2a; color: #4ade80; }
.q-status.attempted { background: #3b2f1f; color: #fbbf24; }
.q-status.empty { background: #1c2230; }
.diff-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.diff-Easy { background: #143527; color: #4ade80; }
.diff-Medium { background: #3a2d10; color: #fbbf24; }
.diff-Hard { background: #3a161c; color: #f87171; }

/* ----- Main panels ----- */
.auth-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  background: #172033;
  border-bottom: 1px solid #2b3650;
}
.auth-banner.hidden { display: none; }
.auth-banner strong {
  display: block;
  color: #fff;
  font-size: 13px;
}
.auth-banner span {
  display: block;
  color: #a7b0c2;
  font-size: 12px;
  margin-top: 1px;
}
.auth-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.auth-banner-actions .hidden { display: none; }
.google-signin-slot iframe {
  display: block;
}
#problem-panel, #editor-panel, #results-panel {
  border-bottom: 1px solid #262b36;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#main.editor-expanded #problem-panel,
#main.editor-expanded #results-panel {
  display: none;
}

#main.editor-expanded #editor-panel {
  grid-row: 2;
  min-height: 0;
}

#problem-panel { overflow-y: auto; padding: 18px 24px; min-height: 360px; }
#problem-header { margin-bottom: 12px; }
#problem-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}
#problem-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: #fff;
}
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-pattern { background: #1c2c4b; color: #93c5fd; }
.badge-tests { background: #1f2937; color: #c5cbd6; text-transform: none; letter-spacing: 0; }
.badge.diff-Easy { background: #143527; color: #4ade80; text-transform: none; letter-spacing: 0; }
.badge.diff-Medium { background: #3a2d10; color: #fbbf24; text-transform: none; letter-spacing: 0; }
.badge.diff-Hard { background: #3a161c; color: #f87171; text-transform: none; letter-spacing: 0; }
.badge-status { background: transparent; color: #4ade80; }

#problem-body {
  color: #c5cbd6;
  font-size: 14px;
  line-height: 1.65;
}
#problem-body h3 { color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; margin: 18px 0 6px; }
#problem-body p { margin: 8px 0; }
#problem-body code {
  background: #1c2230;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: "SF Mono", Monaco, Menlo, monospace;
  font-size: 12.5px;
  color: #fbbf24;
}
#problem-body pre {
  background: #1c2230;
  padding: 10px 14px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12.5px;
}
#problem-body pre code { background: transparent; padding: 0; color: #e6e6e6; }
#problem-body ul { padding-left: 22px; margin: 6px 0; }
#problem-body strong { color: #fff; }

.example-block {
  background: #14181f;
  border: 1px solid #262b36;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 13px;
}
.example-block .ex-row { display: flex; gap: 8px; margin: 2px 0; }
.example-block .ex-label { color: #8a93a3; min-width: 80px; }
.example-block .ex-value { color: #e6e6e6; font-family: "SF Mono", Monaco, Menlo, monospace; }

.placeholder { color: #6b7280; font-style: italic; padding: 12px 0; }

/* ----- Editor ----- */
#editor-panel { background: #0f1115; }
.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #262b36;
  background: #131722;
}
.toolbar-left, .toolbar-right { display: flex; gap: 8px; }
.editor-toolbar > div {
  align-items: center;
  flex-wrap: wrap;
}
#editor {
  flex: 1;
  min-height: 0;
  background: #1e1e1e;
}

.btn {
  border: 1px solid #2a3140;
  background: #1c2230;
  color: #e6e6e6;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover:not(:disabled) { background: #232a3a; border-color: #3a4356; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: white;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #1e40af; border-color: #1e40af; }
.btn-success {
  background: #15803d;
  border-color: #15803d;
  color: white;
}

/* ----- Results ----- */
#results-panel {
  background: #131722;
  border-bottom: none;
}
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #262b36;
}
.results-header h3 { margin: 0; font-size: 13px; color: #c5cbd6; }
.pyodide-status { font-size: 11px; color: #8a93a3; }
.pyodide-status.ready { color: #4ade80; }
.pyodide-status.loading { color: #fbbf24; }
.pyodide-status.error { color: #f87171; }

.results-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  font-family: "SF Mono", Monaco, Menlo, monospace;
  font-size: 12.5px;
}

.result-summary {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
  align-items: center;
}
.summary-passed { color: #4ade80; font-weight: 600; }
.summary-failed { color: #f87171; font-weight: 600; }
.summary-info { color: #8a93a3; }

.test-card {
  background: #1c2230;
  border-left: 3px solid #2a3140;
  border-radius: 4px;
  margin-bottom: 8px;
  padding: 8px 12px;
}
.test-card.pass { border-left-color: #4ade80; }
.test-card.fail { border-left-color: #f87171; }
.test-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: -apple-system, sans-serif;
  font-size: 12.5px;
}
.test-card-header .test-icon { font-size: 13px; }
.test-card-header .test-name { color: #e6e6e6; font-weight: 600; }
.test-card-header .test-hidden { color: #8a93a3; font-size: 10.5px; font-style: italic; }
.test-detail { margin-top: 6px; color: #c5cbd6; }
.test-detail .kv { display: flex; gap: 6px; margin: 2px 0; }
.test-detail .k { color: #8a93a3; min-width: 70px; }
.test-detail .v { color: #e6e6e6; word-break: break-word; }
.test-detail .v.error { color: #f87171; }
.test-detail pre {
  margin: 4px 0 0;
  padding: 6px 8px;
  background: #14181f;
  border-radius: 4px;
  color: #f87171;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.stdout-block {
  margin-top: 10px;
  background: #14181f;
  border: 1px solid #262b36;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 11.5px;
  color: #c5cbd6;
  white-space: pre-wrap;
  word-break: break-word;
}
.stdout-block .stdout-label {
  font-family: -apple-system, sans-serif;
  font-size: 11px;
  color: #8a93a3;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

/* ----- Hint & solution ----- */
.hint-card {
  background: #1f1a0f;
  border-left: 3px solid #fbbf24;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
}
.hint-card .hint-label {
  font-size: 11px;
  color: #fbbf24;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.hint-card .hint-body { color: #e6e6e6; font-family: -apple-system, sans-serif; }

.solution-card {
  background: #14181f;
  border: 1px solid #262b36;
  border-radius: 4px;
  margin-top: 10px;
}
.solution-card .solution-label {
  font-size: 11px;
  color: #8a93a3;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 1px solid #262b36;
}
.complexity-block {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid #262b36;
  background: #171d27;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.complexity-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  align-items: start;
}
.complexity-label {
  color: #8a93a3;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.complexity-value {
  color: #d8dee9;
  font-size: 12.5px;
}
.solution-card pre {
  margin: 0;
  padding: 12px 14px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

/* ----- Modal views ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 13, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}
.modal-backdrop.hidden { display: none; }
.modal {
  width: min(720px, 100%);
  max-height: min(720px, 90vh);
  overflow: hidden;
  background: #14181f;
  border: 1px solid #303747;
  border-radius: 8px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #262b36;
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
}
.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid #2a3140;
  background: #1c2230;
  color: #e6e6e6;
  border-radius: 5px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.modal-body {
  overflow: auto;
  padding: 16px;
}
.profile-card {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.profile-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 16px;
}
.profile-card h3 {
  margin: 0;
  font-size: 15px;
}
.profile-card p {
  margin: 2px 0 0;
  color: #8a93a3;
  font-size: 12.5px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat-grid div {
  background: #1c2230;
  border: 1px solid #262b36;
  border-radius: 6px;
  padding: 10px;
}
.stat-grid strong {
  display: block;
  color: #fff;
  font-size: 20px;
}
.stat-grid span {
  color: #8a93a3;
  font-size: 12px;
}
.modal-section-title {
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 12px 0 8px;
}
.profile-list {
  display: grid;
  gap: 6px;
}
.profile-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  background: #1c2230;
  border: 1px solid #262b36;
  border-radius: 5px;
}
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.score-table th, .score-table td {
  padding: 9px 8px;
  border-bottom: 1px solid #262b36;
  text-align: left;
}
.score-table th {
  color: #8a93a3;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.score-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-form {
  display: grid;
  gap: 8px;
}
.auth-form label {
  color: #8a93a3;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.auth-form input {
  width: 100%;
  padding: 9px 10px;
  background: #0f1115;
  border: 1px solid #2a3140;
  border-radius: 5px;
  color: #e6e6e6;
  outline: none;
}
.auth-form input:focus { border-color: #3b82f6; }
.auth-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.auth-error {
  min-height: 18px;
  color: #f87171;
  font-size: 12px;
}
.auth-note {
  color: #a7b0c2;
  background: #111722;
  border: 1px solid #262b36;
  border-radius: 5px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
}
.auth-note code {
  color: #fbbf24;
  word-break: break-all;
}

/* ----- Scrollbar polish ----- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #131722; }
::-webkit-scrollbar-thumb { background: #2a3140; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4356; }

/* ----- Responsive: stack on narrow screens ----- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
  #sidebar { border-right: none; border-bottom: 1px solid #262b36; }
  #main {
    grid-template-rows: auto minmax(360px, auto) minmax(340px, auto) minmax(130px, auto);
  }
}
