:root {
  color-scheme: light;
  --ink: #111111;
  --muted: #717171;
  --line: #e7e7e7;
  --soft: #f6f6f6;
  --paper: #ffffff;
  --max: 760px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); }
body { margin: 0; min-height: 100dvh; background: var(--paper); }
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus, button:focus-visible { outline: 0; box-shadow: none; }

.app-shell { width: min(100%, var(--max)); margin: 0 auto; padding: 0 20px 80px; }
.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.brand img { opacity: .84; }
.icon-button, .close-button, .back-button { border: 0; background: transparent; cursor: pointer; }
.icon-button { font-weight: 700; letter-spacing: 2px; padding: 10px 0 10px 14px; }

.search-wrap { position: relative; }
#search { width: 100%; height: 58px; padding: 0; border: 0; border-bottom: 1px solid var(--ink); outline: 0; background: transparent; color: var(--ink); font-size: clamp(25px, 5vw, 36px); font-weight: 500; letter-spacing: -.035em; border-radius: 0; }
#search::placeholder { color: #a1a1a1; opacity: 1; }
#search::-webkit-search-cancel-button { display: none; }
.status { padding: 10px 0 4px; color: var(--muted); font-size: 13px; }
.status:empty { display: none; }

.results { border-top: 1px solid var(--line); }
.result { min-height: 64px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); outline: 0; }
.result:focus, .result[data-selected="true"] { background: var(--soft); box-shadow: none; }
.result-main { flex: 1; min-width: 0; padding: 10px 0; cursor: pointer; }
.result-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 560; }
.result-title .arrow { color: #777; font-size: 19px; }
.result-meta { color: var(--muted); font-size: 13px; margin-top: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.result-actions { display: flex; gap: 6px; }
.action-button { min-width: 42px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-size: 12px; cursor: pointer; }
.action-button.icon-action { width: 36px; min-width: 36px; display: grid; place-items: center; padding: 0; }
.action-button.icon-action, .action-button.more-action { border-color: transparent; background: transparent; }
.action-button.search-action { min-width: auto; padding: 0 14px; border-radius: 16px; }
.action-button.icon-action img { width: 18px; height: 18px; opacity: .76; }
.action-button:hover { background: var(--soft); }
.action-button.search-action:hover { border-color: #aaa; }
.empty-state { padding: 56px 0; color: var(--muted); text-align: center; }

.toast { position: fixed; inset: auto auto calc(22px + env(safe-area-inset-bottom)) 50%; margin: 0; z-index: 30; transform: translate(-50%, 14px); padding: 10px 15px; border: 0; border-radius: 999px; background: #111; color: white; font-size: 13px; opacity: 0; pointer-events: none; transition: .18s ease; }
.toast.visible, .toast:popover-open { opacity: 1; transform: translate(-50%, 0); }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.22); backdrop-filter: blur(2px); }
.sheet-dialog, .settings-dialog, .search-service-dialog { width: min(calc(100% - 28px), 620px); max-height: min(82dvh, 720px); padding: 0; border: 1px solid #d8d8d8; border-radius: 18px; background: var(--paper); box-shadow: 0 24px 70px rgba(0,0,0,.14); }
.dialog-head { min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { flex: 1; margin: 0; font-size: 17px; }
.back-button, .close-button { font-size: 24px; padding: 8px; }
.details-list { max-height: calc(82dvh - 65px); overflow: auto; padding: 0 18px 20px; }
.detail { padding: 18px 0; border-bottom: 1px solid var(--line); }
.detail:last-child { border-bottom: 0; }
.detail h3 { margin: 0 0 8px; font-size: 15px; }
.detail-text { margin: 0; color: #333; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 8px; margin-top: 13px; }
.actions-list { padding: 8px 18px 18px; }
.action-row { width: 100%; min-height: 50px; display: flex; align-items: center; justify-content: space-between; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left; }
.action-row:last-child { border-bottom: 0; }
.action-row:hover, .action-row:focus-visible { background: var(--soft); outline: 0; }
.action-row kbd { min-width: 30px; color: var(--muted); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }
.preview-body { min-height: 140px; max-height: calc(82dvh - 130px); overflow: auto; padding: 22px 20px; color: #272727; line-height: 1.58; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

.settings-dialog form { padding-bottom: 20px; }
.settings-dialog form > p, .settings-dialog form > label, .settings-dialog form > textarea, .settings-dialog .form-actions { margin-left: 20px; margin-right: 20px; }
.settings-dialog form > p { color: var(--muted); line-height: 1.45; }
.settings-dialog label { display: block; margin-top: 20px; font-size: 13px; font-weight: 650; }
.settings-dialog textarea { display: block; width: calc(100% - 40px); margin-top: 8px; resize: vertical; border: 1px solid #ccc; border-radius: 10px; padding: 12px; outline: none; }
.settings-dialog textarea:focus { border-color: var(--ink); }
.form-note { font-size: 12px; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }
.form-actions-right { display: flex; gap: 10px; }
.search-service-dialog form { padding-bottom: 20px; }
.search-service-dialog #service-query { width: calc(100% - 40px); height: 52px; margin: 20px; padding: 0 2px; border: 0; border-bottom: 1px solid var(--ink); border-radius: 0; outline: 0; font-size: 24px; }
.search-service-dialog .primary-button { display: block; margin: 0 20px 0 auto; }
.primary-button, .secondary-button { border-radius: 9px; padding: 10px 15px; cursor: pointer; }
.primary-button { border: 1px solid var(--ink); background: var(--ink); color: white; }
.secondary-button { border: 1px solid var(--line); background: white; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 640px) {
  .app-shell { padding: 0 16px 68px; }
  .topbar { height: 58px; }
  #search { height: 54px; font-size: 28px; }
  .result { min-height: 62px; }
  .action-button { min-width: 44px; }
  .sheet-dialog, .search-service-dialog { width: 100%; max-width: none; max-height: 88dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; }
  .details-list { max-height: calc(88dvh - 65px); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .preview-body { min-height: 34dvh; max-height: calc(88dvh - 130px); }
  .settings-dialog .form-actions { align-items: stretch; }
  .settings-dialog .form-actions-right { flex: 1; justify-content: flex-end; }
}

@media (min-width: 760px) {
  .topbar { height: 84px; }
}
