:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --paper: #fffdf8;
  --panel: #ffffff;
  --line: #d8ded7;
  --text: #20262d;
  --muted: #68716b;
  --accent: #2f6f5e;
  --accent-dark: #255849;
  --danger: #b42318;
  --warn: #a15c07;
  --blue: #315f9f;
  --green: #28734f;
  --orange: #b85c12;
  --red: #b42318;
  --shadow: 0 8px 18px rgba(32, 38, 45, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(47, 111, 94, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 111, 94, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  border: 1px solid #ccd5cf;
  background: #f4f6f4;
  color: var(--text);
}

button.secondary:hover {
  background: #e9eee9;
}

button.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: white;
  color: var(--text);
  font-size: 16px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px 22px;
}

.install-app-button {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 20;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(32, 38, 45, 0.12);
  border-radius: 6px;
  background: var(--text);
  box-shadow: 0 6px 14px rgba(32, 38, 45, 0.14);
  font-size: 12px;
}

.install-app-button:hover {
  background: #364152;
}

.auth-panel {
  width: min(420px, 100%);
  margin: 10vh auto 0;
  padding: 26px 28px 24px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 7px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
}

.auth-form {
  display: grid;
  gap: 13px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.app-view {
  display: grid;
  gap: 16px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 16px;
  border: 0;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  background: transparent;
}

.app-header h1 {
  font-size: 28px;
}

.app-header .eyebrow {
  margin-bottom: 5px;
}

.session-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.session-box span:first-child {
  font-size: 14px;
  font-weight: 800;
}

.save-status {
  min-width: 70px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #fffdf8;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eef4f0;
}

.tab-button {
  width: 100%;
}

.tab-panel {
  display: grid;
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 8px;
}

.summary-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  min-height: 74px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.summary-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.summary-card strong {
  font-size: 23px;
}

.summary-card small {
  grid-column: 1 / -1;
  color: var(--warn);
  font-size: 12px;
}

.ms-result-panel {
  display: grid;
  gap: 12px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 7px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.ms-result-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.ms-result-main span,
.ms-result-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.ms-result-main div {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.ms-result-main strong {
  color: var(--accent-dark);
  font-size: 34px;
  line-height: 1;
}

.ms-result-main em {
  color: var(--muted);
  font-size: 15px;
  font-style: normal;
  font-weight: 800;
}

.ms-result-main p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.ms-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ms-result-grid article {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid #dfe6e0;
  border-radius: 7px;
  background: #ffffff;
}

.ms-result-grid strong {
  font-size: 17px;
}

.ms-section {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(32, 38, 45, 0.04);
}

.ms-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf7;
}

.toggle-card h3 {
  margin: 0;
  font-size: 17px;
}

.toggle-card p,
.input-notice,
.field-help {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toggle-inline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}

.toggle-inline input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
  accent-color: var(--accent);
}

.toggle-state {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  min-height: 30px;
  border-radius: 6px;
  background: var(--text);
  color: white;
  font-size: 13px;
  font-weight: 900;
}

.ms-form {
  display: grid;
  gap: 10px;
}

.semester-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.semester-card[hidden] {
  display: none;
}

.semester-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 13px 14px;
  background: #eef4f0;
  cursor: pointer;
  list-style: none;
}

.semester-card summary::-webkit-details-marker {
  display: none;
}

.semester-card summary span {
  font-weight: 900;
}

.semester-card summary em {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.semester-mode-panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 0;
  border-top: 1px solid #e1e7e2;
  background: #ffffff;
}

.semester-mode-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  min-width: 240px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f4f6f4;
}

.semester-mode-tabs label {
  position: relative;
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.semester-mode-tabs input {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 100%;
  opacity: 0;
  cursor: pointer;
}

.semester-mode-tabs span {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 5px;
  padding: 0 10px;
  text-align: center;
}

.semester-mode-tabs input:checked + span {
  background: var(--accent);
  color: white;
}

.semester-direct-score {
  width: min(240px, 100%);
}

.semester-direct-score input {
  text-align: right;
}

.semester-subject-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
  padding: 10px;
}

.ms-subject-row {
  display: grid;
  grid-template-columns: minmax(76px, 1fr) minmax(96px, 118px) minmax(96px, 118px);
  align-items: end;
  gap: 9px;
  padding: 10px;
  border: 1px solid #e4e9e5;
  border-radius: 7px;
  background: #fbfcfb;
}

.ms-subject-row strong {
  align-self: center;
  font-size: 15px;
}

.ms-subject-row.is-locked {
  background: #f2f4f2;
}

.ms-subject-row.is-locked strong,
.ms-subject-row.is-locked label span {
  color: #5c665f;
}

.ms-subject-row.is-locked input,
.ms-subject-row.is-locked select {
  border-color: #d5dcd6;
  background: #eef1ef;
  color: #4f5a53;
  font-weight: 800;
  opacity: 1;
}

.ms-subject-row label,
.extra-grid label {
  gap: 5px;
  min-width: 0;
}

.ms-subject-row label span,
.extra-grid label span {
  color: var(--muted);
  font-size: 12px;
}

.extra-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

fieldset {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
}

legend {
  padding: 0 5px;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
}

.attendance-grid {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.attendance-grid span,
.attendance-grid strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.attendance-grid input {
  min-width: 0;
}

.save-status[data-status="saving"],
.save-status[data-status="pending"] {
  border-color: #f6c56f;
  color: var(--warn);
}

.save-status[data-status="error"] {
  border-color: #f0a29a;
  color: var(--danger);
}

.subjects-root {
  display: grid;
  gap: 14px;
}

.subject-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(32, 38, 45, 0.04);
}

.subject-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8faf7;
}

.subject-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.subject-score {
  display: flex;
  align-items: center;
  gap: 10px;
}

.subject-score strong {
  min-width: 64px;
  text-align: right;
  font-size: 26px;
}

.grade {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  border-radius: 6px;
  color: white;
  font-style: normal;
  font-weight: 900;
}

.grade-a {
  background: var(--blue);
}

.grade-b {
  background: var(--green);
}

.grade-c {
  background: var(--orange);
}

.grade-d {
  background: var(--red);
}

.grade-e {
  background: #6f3f3f;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #eef4f0;
  color: #364152;
  font-size: 12px;
  white-space: nowrap;
}

td {
  font-size: 14px;
}

td:nth-child(1),
td:nth-child(2),
td:nth-child(3),
td:nth-child(6),
td:nth-child(7) {
  width: 92px;
  text-align: center;
}

td:nth-child(4) {
  width: 116px;
}

td input {
  min-width: 86px;
  text-align: right;
}

.item-result {
  font-weight: 800;
}

.unknown {
  color: var(--warn);
  font-weight: 800;
}

@media (max-width: 720px) {
  .shell {
    padding: 12px;
  }

  .install-app-button {
    top: 8px;
    right: 8px;
    min-height: 30px;
    padding: 0 9px;
  }

  .auth-panel {
    width: 100%;
    max-width: 360px;
    margin: 5vh auto 0;
    padding: 20px;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }

  .app-header,
  .subject-header {
    align-items: stretch;
    flex-direction: column;
  }

  .session-box {
    justify-content: flex-start;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab-list {
    gap: 6px;
  }

  .ms-result-main {
    align-items: flex-start;
    flex-direction: column;
  }

  .ms-result-main strong {
    font-size: 32px;
  }

  .ms-result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ms-section {
    padding: 12px;
  }

  .ms-section-header,
  .toggle-card {
    align-items: stretch;
    flex-direction: column;
  }

  .toggle-inline {
    justify-content: space-between;
    width: 100%;
  }

  .semester-subject-list {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .semester-mode-panel {
    align-items: stretch;
    flex-direction: column;
    padding: 8px 8px 0;
  }

  .semester-mode-tabs,
  .semester-direct-score {
    width: 100%;
    min-width: 0;
  }

  .ms-subject-row {
    grid-template-columns: 1fr 1fr;
  }

  .ms-subject-row strong {
    grid-column: 1 / -1;
  }

  .extra-grid {
    grid-template-columns: 1fr;
  }

  .attendance-grid {
    grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100% !important;
    min-height: 36px;
    border: 0;
    padding: 5px 0;
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  td[data-label="과목명"]:empty {
    display: none;
  }

  td input {
    min-width: 0;
  }
}
