:root {
  color-scheme: light;
  --notes-bg: #f2f1f6;
  --paper: #ffffff;
  --ink: #111114;
  --muted: #86868b;
  --line: #dedee4;
  --accent: #111114;
  --accent-strong: #111114;
  --control-bg: #111315;
  --control-panel: #1c2024;
  --control-line: #343a40;
  --control-ink: #f4f5f6;
  --control-muted: #a7b0b7;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  position: fixed;
  inset: 0;
  background: var(--notes-bg);
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
}

[hidden] {
  display: none !important;
}

.app-shell,
.display-view,
.notes-screen,
.note-detail-screen {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

.login-screen {
  height: 100dvh;
  overflow-y: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, #f8f8f5 0%, #ece9de 100%);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 0 20px 60px rgba(30, 28, 20, 0.12);
}

.login-kicker,
.control-kicker {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.login-card h1,
.control-header h1,
.settings-header h1 {
  margin: 0 0 22px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

.login-card label,
.field {
  display: grid;
  gap: 7px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-card input,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid #d7d2c4;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
  font-size: 16px;
}

.field textarea {
  resize: vertical;
  line-height: 1.45;
}

.login-card button,
.send-number-btn,
.settings-actions button,
.manager-head button,
.editor-toolbar button,
.mode-sheet-card button {
  min-height: 44px;
  border-radius: 7px;
  background: var(--accent);
  color: #17130a;
  font-weight: 800;
}

.login-card button {
  width: 100%;
  margin-top: 12px;
}

.login-note,
.editor-help,
.remote-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.notes-screen {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100dvh;
  background: var(--notes-bg);
  overflow: hidden;
  overscroll-behavior: none;
  padding: max(8px, env(safe-area-inset-top)) 24px max(24px, calc(env(safe-area-inset-bottom) + 20px));
}

.notes-header,
.detail-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  flex: 0 0 auto;
}

.notes-round-btn,
.detail-actions button {
  width: 44px;
  height: 44px;
  position: relative;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  color: #111114;
  box-shadow: 0 13px 30px rgba(36, 36, 43, 0.12);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  display: grid;
  place-items: center;
  line-height: 1;
}

.notes-back-glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 13px;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: translate(-38%, -50%) rotate(45deg);
  border-radius: 1px;
}

.notes-more-glyph::before,
.detail-more-glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: -8px 0 0 currentColor, 8px 0 0 currentColor;
  transform: translate(-50%, -50%);
}

.detail-share-glyph::before {
  content: "\2191";
  font-size: 27px;
  font-weight: 500;
  transform: translateY(-2px);
}

.detail-actions .detail-more-glyph {
  width: 44px;
  border-radius: 22px;
}

.hidden-hotspot {
  width: 120px;
  height: 44px;
  background: transparent;
  pointer-events: none;
}

.notes-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.notes-title-row h1 {
  margin: 10px 0 28px;
  font-size: clamp(34px, 9vw, 38px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
}

.notes-list {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 30px;
  background: var(--paper);
  border: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.note-row {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  padding: 10px 40px 9px;
  border-bottom: 1px solid #e3e3e7;
  background: transparent;
  text-align: left;
  color: var(--ink);
}

.note-row:last-child {
  border-bottom: 0;
}

.note-row strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  line-height: 1.25;
  font-weight: 760;
}

.note-row > span {
  min-width: 0;
}

.note-row p {
  margin: 2px 0 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 500;
}

.empty-notes {
  padding: 26px 40px;
  color: var(--muted);
  line-height: 1.5;
}

.note-detail-screen {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  padding: max(8px, env(safe-area-inset-top)) 24px max(26px, calc(env(safe-area-inset-bottom) + 22px));
}

.detail-actions {
  display: flex;
  gap: 12px;
}

.detail-actions button {
  width: 44px;
  height: 44px;
}

.note-paper {
  flex: 1;
  max-width: 720px;
  width: 100%;
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 auto;
  padding: 32px 0 26px;
}

.detail-date {
  display: none;
  margin: 0 0 12px;
  color: #9a958b;
  text-align: center;
  font-size: 13px;
}

.note-paper h2 {
  margin: 0 0 42px;
  color: #4f4f55;
  font-size: clamp(28px, 7.6vw, 34px);
  line-height: 1.2;
  font-weight: 760;
  letter-spacing: 0;
}

.detail-words {
  margin: 0;
  padding-left: 2.5em;
  list-style-position: outside;
  font-size: clamp(21px, 5.35vw, 27px);
  line-height: 1.45;
  color: #4f4f55;
  font-weight: 520;
}

.detail-words li {
  padding-left: 0.18em;
}

.remote-view {
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, calc(env(safe-area-inset-bottom) + 16px));
  background: var(--control-bg);
  color: var(--control-ink);
  overflow-y: auto;
}

.control-header,
.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 900px;
  margin: 0 auto 12px;
}

.control-header h1,
.settings-header h1 {
  margin-bottom: 0;
}

.remote-view .control-kicker {
  margin-bottom: 3px;
  color: var(--control-muted);
  font-size: 10px;
}

.remote-view .control-header h1 {
  font-size: 24px;
  line-height: 1.05;
}

.control-ghost-btn,
.settings-actions button,
.editor-toolbar button,
.manager-head button {
  padding: 0 14px;
}

.control-ghost-btn {
  min-height: 40px;
  border-radius: 7px;
  background: #2b3035;
  color: var(--control-ink);
  font-weight: 800;
}

.remote-status-band,
.remote-range {
  max-width: 900px;
  margin: 0 auto 8px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--control-panel);
}

.remote-status-band {
  min-height: 48px;
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 12px;
  align-items: center;
  padding: 9px 14px;
}

.conn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.15);
}

.conn-dot.ready {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14);
}

.conn-dot.bad {
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.14);
}

.remote-status-band small {
  display: none;
}

.remote-range {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  color: var(--control-muted);
}

.remote-range strong {
  color: var(--control-ink);
  font-size: 22px;
}

.remote-status-band[hidden],
.remote-range[hidden] {
  display: none;
}

.remote-number-input {
  display: block;
  width: min(100%, 900px);
  height: 58px;
  margin: 8px auto;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: #090b0d;
  color: var(--control-ink);
  text-align: center;
  font-size: 34px;
  font-weight: 800;
  caret-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.number-pad {
  width: min(100%, 420px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 auto 12px;
}

.number-pad button {
  height: clamp(46px, 8dvh, 62px);
  border-radius: 8px;
  background: #2a3036;
  color: var(--control-ink);
  font-size: 25px;
  font-weight: 800;
}

.number-pad button.utility {
  background: #3b424a;
  font-size: 16px;
}

.send-number-btn {
  display: block;
  width: min(100%, 420px);
  height: 58px;
  margin: 0 auto 10px;
  background: #f4c430;
  color: #111315;
  font-size: 18px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.send-number-btn:disabled {
  opacity: 1;
  background: #56616d;
  color: #f7f8fb;
  box-shadow: none;
}

.remote-hint {
  max-width: 460px;
  margin: 0 auto;
  color: var(--control-muted);
  font-size: 12px;
}

.settings-view {
  height: 100dvh;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
  background: #f1f2ee;
}

.settings-header {
  color: var(--ink);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.settings-actions button,
.manager-head button,
.editor-toolbar button {
  background: #252a2f;
  color: #fff;
}

.settings-actions #logoutBtn,
.danger-btn {
  background: #7f1d1d;
}

.settings-layout {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.memo-manager,
.memo-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.memo-manager {
  overflow: hidden;
}

.manager-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.manager-head h2 {
  margin: 0;
  font-size: 18px;
}

.manager-actions {
  display: flex;
  gap: 6px;
}

.setup-memo-list {
  display: grid;
}

.fake-manager-head {
  border-top: 1px solid var(--line);
}

.setup-memo-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #ece8dc;
  background: transparent;
  text-align: left;
}

.setup-memo-item.reorder-mode {
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  cursor: grab;
}

.setup-memo-item.dragging {
  opacity: 0.62;
  background: #eef2f7;
}

.setup-memo-select {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 4px;
  background: transparent;
  text-align: left;
}

.reorder-mode .setup-memo-select {
  pointer-events: none;
}

.setup-memo-item.active {
  background: #f5edcf;
}

.fake-memo-item.active {
  background: #e8edf4;
}

.setup-memo-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setup-memo-item span {
  color: var(--muted);
  font-size: 12px;
}

.drag-handle,
.delete-list-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-weight: 900;
}

.drag-handle {
  background: #ece8dc;
  color: #525252;
  cursor: grab;
  touch-action: none;
  line-height: 1;
}

.delete-list-btn {
  background: #ead8d8;
  color: #7f1d1d;
  font-size: 18px;
}

.is-list-dragging {
  cursor: grabbing;
  user-select: none;
}

.fake-empty {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
}

.memo-editor {
  padding: 14px;
}

.word-panel {
  margin: 14px 0 0;
}

.word-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.word-panel-head button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 7px;
  background: #252a2f;
  color: #fff;
  font-weight: 800;
}

#bulkWords {
  width: 100%;
  min-height: 420px;
  border: 1px solid #d7d2c4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
  resize: vertical;
  font-size: 16px;
  line-height: 1.45;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.memo-editor:not(.word-editing) .editor-toolbar {
  display: none;
}

.memo-editor.fake-editing .word-panel,
.memo-editor.fake-editing .editor-toolbar,
.memo-editor.fake-editing .editor-help {
  display: none;
}

.word-rows {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 420px;
  max-height: min(58dvh, 620px);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #d7d2c4;
  border-radius: 8px;
  background: #fff;
}

.word-row {
  display: grid;
  grid-template-columns: 30px 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 5px 8px;
  border: 1px solid #ece8dc;
  border-radius: 7px;
  background: #fffdf8;
}

.word-row-number {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.word-row input[type="radio"] {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #b9b4a7;
  border-radius: 50%;
  background: #fff;
  accent-color: var(--accent-strong);
}

.word-row input[type="radio"]::after {
  content: "";
  width: 11px;
  height: 6px;
  border-left: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
  opacity: 0;
}

.word-row input[type="radio"]:checked {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.word-row input[type="radio"]:checked::after {
  opacity: 1;
}

.word-row-text {
  min-width: 0;
  font-size: 16px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fake-note-row {
  cursor: default;
}

.mode-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.22);
}

.mode-sheet-card {
  width: min(420px, 100%);
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
}

.mode-sheet-card button {
  width: 100%;
}

.mode-sheet-card #closeModeSheetBtn {
  background: #e8e4da;
}

@media (max-width: 760px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .control-header,
  .settings-header {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-actions {
    justify-content: stretch;
  }

  .settings-actions button {
    flex: 1;
  }

  .word-row {
    grid-template-columns: 28px 38px minmax(0, 1fr);
    gap: 6px;
  }

  #bulkWords,
  .word-rows {
    min-height: 360px;
  }

  .detail-words {
    font-size: 18px;
    padding-left: 2.7em;
  }
}
