:root {
  color-scheme: light dark;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
}

html[data-theme="light"] {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-hover: #f0efe9;
  --text: #1b1b19;
  --text-dim: #6f6e68;
  --border: #e3e1d9;
  --accent: #5b52e0;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --danger-bg: #fbeae7;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 8px 24px rgba(20, 20, 15, 0.06);
}

html[data-theme="dark"] {
  --bg: #131215;
  --surface: #1b1a1e;
  --surface-hover: #232227;
  --text: #ece9e4;
  --text-dim: #93908a;
  --border: #2d2c31;
  --accent: #8b83ff;
  --accent-text: #131215;
  --danger: #ff7a6b;
  --danger-bg: #2a1a19;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  flex-shrink: 0;
}

.brand {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status {
  font-size: 13px;
  color: var(--text-dim);
  margin-right: 6px;
  min-width: 110px;
  text-align: right;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ------------------------------------------------------------------ main */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------- gate view */

#gate-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 28px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.gate-card h1 {
  font-size: 18px;
  margin: 0 0 6px;
}

.gate-card .hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 20px;
  line-height: 1.4;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-ui);
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.password-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.password-row input {
  flex: 1;
}

.text-btn {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 2px;
  white-space: nowrap;
}

.text-btn:hover {
  color: var(--text);
}

.error-msg {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 14px;
}

.primary-btn {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  opacity: 0.92;
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.doc-list-wrap {
  width: 100%;
  max-width: 360px;
}

.doc-list-wrap h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-list li button {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.doc-list li button:hover {
  background: var(--surface);
  border-color: var(--border);
}

.doc-list li .doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-list li .doc-time {
  color: var(--text-dim);
  font-size: 12px;
  flex-shrink: 0;
}

/* ----------------------------------------------------------- editor view */

.editor-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 24px 40px;
}

.editor-title {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 12px;
}

#editor {
  flex: 1;
  width: 100%;
  border: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.7;
  padding: 0;
}

#editor:focus {
  outline: none;
}

#editor::placeholder {
  color: var(--text-dim);
}

@media (max-width: 600px) {
  .editor-shell {
    padding: 6px 18px 30px;
  }
  #editor {
    font-size: 17px;
  }
}
