:root {
  color-scheme: light;
  --brand: #0f548c;
  --header-background: #0f548c;
  --accent: #0f6cbd;
  --text: #242424;
  --muted: #5f6368;
  --shell: #eef3f7;
  --surface: #ffffff;
  --inbox: #f7f9fb;
  --line: #dce3e9;
  --hover: #edf3f7;
  --selected: #e3eff8;
  --error: #a4262c;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--shell);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --brand: #479ef5;
    --header-background: #1f1f1f;
    --accent: #479ef5;
    --text: #ffffff;
    --muted: #adadad;
    --shell: #141414;
    --surface: #292929;
    --inbox: #1f1f1f;
    --line: #424242;
    --hover: #333333;
    --selected: #0a2e4a;
    --error: #f1707b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

[hidden] {
  display: none !important;
}

#login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.login-card {
  width: 100%;
  max-width: 340px;
  padding: 32px 0;
}

.login-brand {
  display: flex;
  justify-content: center;
  color: var(--brand);
}

.login-brand svg {
  flex: 0 0 auto;
}

.login-card h1 {
  margin: 24px 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 8vw, 42px);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.035em;
  text-align: center;
}

.login-intro {
  margin: 0 0 44px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}

.login-field + .login-field {
  margin-top: 24px;
}

.login-field label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.login-field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 2px;
  border: 0;
  border-bottom: 1px solid var(--muted);
  border-radius: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
}

.login-field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.login-field input[aria-invalid="true"] {
  border-color: var(--error);
}

#login-error {
  min-height: 20px;
  margin: 12px 0;
  color: var(--error);
  font-size: 13px;
  line-height: 1.5;
}

#sign-in {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--brand);
  color: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

@media (hover: hover) and (pointer: fine) {
  #sign-in:hover:not(:disabled) {
    background: var(--accent);
  }
}

#sign-in:active:not(:disabled) {
  transform: translateY(1px);
}

@media (prefers-reduced-motion: reduce) {
  #sign-in:active:not(:disabled) {
    transform: none;
  }
}

#sign-in:focus-visible {
  outline-offset: 3px;
}

#sign-in:disabled {
  cursor: default;
  opacity: 0.6;
}

.login-help {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.login-note {
  margin: 24px 0 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
  line-height: 1.6;
  text-align: center;
}

#sign-out, #show-report {
  margin-left: auto;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid currentColor;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 13px;
}

#sign-out:hover {
  background: rgb(255 255 255 / 10%);
}

#sign-out:focus-visible {
  outline-color: currentColor;
}

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: calc(10px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 10px max(24px, env(safe-area-inset-left));
  color: #ffffff;
  background: var(--header-background);
}

.app-icon {
  flex: 0 0 auto;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
}

.mailbox {
  display: grid;
  grid-template-columns: clamp(280px, var(--inbox-width, clamp(300px, 28vw, 380px)), calc(100% - 368px)) 8px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

#inbox-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--inbox);
}

#panel-resizer {
  cursor: col-resize;
  touch-action: none;
  background: linear-gradient(to right, transparent 3px, var(--line) 3px, var(--line) 4px, transparent 4px);
}

#panel-resizer:hover,
#panel-resizer:focus-visible,
.is-resizing #panel-resizer {
  background: linear-gradient(to right, transparent 3px, var(--accent) 3px, var(--accent) 5px, transparent 5px);
}

.is-resizing,
.is-resizing * {
  cursor: col-resize !important;
  user-select: none;
}

.inbox-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.inbox-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
}

#unread-count {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#sort-order {
  flex-shrink: 0;
  margin-left: auto;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

#sort-order:hover {
  background: var(--hover);
  color: var(--text);
}

#letter-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.letter-row {
  position: relative;
  display: block;
  width: 100%;
  min-height: 106px;
  padding: 17px 22px 17px 24px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  line-height: 1.5;
  transition: background-color 150ms ease;
}

.letter-row:hover {
  background: var(--hover);
}

.letter-row.is-selected {
  background: var(--selected);
  box-shadow: inset 3px 0 var(--accent);
}

.letter-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 3px;
}

.letter-sender {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.letter-date {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.letter-subject,
.letter-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.letter-subject {
  font-size: 14px;
}

.letter-preview {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.is-unread .letter-subject,
.is-unread .letter-sender {
  font-weight: 600;
}

.is-unread .letter-subject {
  color: var(--brand);
}

.unread-dot {
  position: absolute;
  top: 25px;
  left: 10px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.letter-row:not(.is-unread) .unread-dot {
  display: none;
}

#reader-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  background: var(--surface);
}

.reader-toolbar {
  display: flex;
  justify-content: flex-end;
  min-height: 60px;
  padding: 8px 16px;
}

#close-letter {
  min-width: 44px;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}

#close-letter:hover {
  background: var(--hover);
  color: var(--text);
}

.mobile-back {
  display: none;
}

.letter-content {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 44px 80px;
  overflow-wrap: anywhere;
}

.letter-header h1 {
  margin: 0 0 24px;
  font-family: Georgia, "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: 30px;
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: -0.4px;
}

.letter-sent-date {
  display: block;
  margin: -12px 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.song-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 32px;
}

.song-button {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
  transition: background-color 150ms ease;
}

.song-button:hover {
  background: var(--hover);
}

.song-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--selected);
}

.song-action {
  flex: 0 0 auto;
  min-width: 36px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
}

.song-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.song-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.song-artist {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.letter-body {
  font-size: 17px;
  line-height: 1.71;
}

.letter-body p {
  margin: 0 0 1.4em;
}

.letter-body strong {
  font-weight: 600;
}

.letter-body hr {
  margin: 1.4em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.letter-visual {
  margin: 1.4em 0;
}

.letter-visual img,
.letter-visual video {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

#player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 24px;
  padding: 12px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.player-track {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  overflow-wrap: anywhere;
}

#player-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

#player-artist {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

#player-toggle {
  min-width: 76px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--brand);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

#player-toggle:hover {
  background: var(--hover);
}

#player-error {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  color: var(--error);
  font-size: 13px;
  line-height: 1.5;
}

#player-error:empty {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1000px) {
  .letter-content {
    padding-right: 28px;
    padding-left: 28px;
  }
}

@media (max-width: 720px) {
  #panel-resizer {
    display: none;
  }

  .app-header {
    min-height: 52px;
    padding-right: max(20px, env(safe-area-inset-right));
    padding-left: max(20px, env(safe-area-inset-left));
  }

  .mailbox {
    display: block;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  #inbox-panel,
  #reader-panel {
    height: 100%;
    border: 0;
  }

  #reader-panel {
    display: none;
  }

  .has-selection #inbox-panel {
    display: none;
  }

  .has-selection #reader-panel {
    display: block;
  }

  .inbox-header {
    min-height: 64px;
    padding-left: max(24px, env(safe-area-inset-left));
  }

  .letter-row {
    padding-right: max(24px, env(safe-area-inset-right));
    padding-left: max(24px, env(safe-area-inset-left));
  }

  .reader-toolbar {
    justify-content: flex-start;
    padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  }

  #close-letter {
    color: var(--brand);
  }

  .desktop-close {
    display: none;
  }

  .mobile-back {
    display: inline;
  }

  .letter-content {
    padding: 12px max(24px, env(safe-area-inset-right)) 48px max(24px, env(safe-area-inset-left));
  }

  .letter-header h1 {
    margin-bottom: 20px;
    font-size: 27px;
  }

  .letter-body {
    line-height: 1.665;
  }

  .song-list {
    flex-direction: column;
    align-items: flex-start;
  }

  #player {
    gap: 0 16px;
    padding-right: max(20px, env(safe-area-inset-right));
    padding-left: max(20px, env(safe-area-inset-left));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* Keeps the author report within the mailbox palette and readable on narrow screens. */
#report { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
#report h1 { font-size: 24px; }
#report p { max-width: 760px; line-height: 1.6; }
.report-scroll { overflow-x: auto; }
#report table { width: 100%; border-collapse: collapse; text-align: left; }
#report th, #report td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
#report th { white-space: nowrap; }
#show-report { margin-left: auto; }

#show-report:not([hidden]) + #sign-out { margin-left: 0; }

#report-back { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--brand); background: var(--surface); }
