:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --panel: #fffaf0;
  --panel-strong: #fff4dc;
  --ink: #172027;
  --muted: #66727c;
  --line: #dfd4c1;
  --accent: #1f7a6d;
  --accent-strong: #155e55;
  --danger: #b73737;
  --gold: #c69226;
  --shadow: 0 14px 40px rgba(24, 31, 37, 0.14);
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}
[hidden] { display: none !important; }
.login-screen { min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.login-screen h1 { margin: 0; font-size: 26px; }

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 0 10px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 21px;
  line-height: 1.05;
}

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

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #172027;
  color: white;
  font-size: 24px;
  line-height: 1;
}

.search-panel,
.content-grid {
  max-width: 1180px;
  margin: 0 auto;
}

.search-panel {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 10px 0;
  background: var(--bg);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px;
}

.search-row input,
dialog input,
dialog select,
dialog textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  outline: none;
}

.search-row input {
  min-height: 48px;
  padding: 0 13px;
  font-size: 17px;
}

.search-row input:focus,
dialog input:focus,
dialog select:focus,
dialog textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.18);
}

.search-row button,
.tab,
.primary,
.danger {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

#pasteButton {
  background: #25323b;
  color: white;
}

#addButton,
.primary {
  background: var(--accent);
  color: white;
}

#addButton {
  width: 50px;
  font-size: 28px;
  line-height: 1;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.tab {
  background: var(--panel-strong);
  color: var(--ink);
  border: 1px solid var(--line);
}

.tab.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 12px;
  padding-bottom: 18px;
}

.results-panel,
.details-panel {
  min-height: calc(100vh - 150px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.results-list {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 158px);
  overflow: auto;
}

.result-item {
  display: block;
  width: 100%;
  min-height: 58px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.result-item.active {
  background: #e5f4ef;
}

.result-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

.room-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #172027;
  color: white;
  font-size: 12px;
  padding: 3px 8px;
}

.result-preview {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.details-panel {
  padding: 16px;
  overflow: auto;
}

.empty-state {
  display: grid;
  min-height: calc(100vh - 184px);
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.details-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.details-head h2 {
  font-size: 25px;
  overflow-wrap: anywhere;
}

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

.details-head > div:first-child { min-width: 0; }
.details-actions { flex: 0 0 auto; }
.tool-button, .icon-button { display: inline-flex; align-items: center; justify-content: center; }
.tool-button { width: 38px; padding: 0; }
button svg { width: 20px; height: 20px; flex-shrink: 0; }
.identity-aliases { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.alias-link { padding: 5px 0; background: transparent; color: var(--accent-strong); text-align: left; overflow-wrap: anywhere; }
.identity-source { display: block; margin-top: 7px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.alias-row { display: grid; grid-template-columns: minmax(0, 1fr) 112px 38px; gap: 6px; margin-bottom: 6px; align-items: center; }
.alias-row input, .alias-row select { min-width: 0; }
.form-error { font-size: 13px; color: var(--danger); overflow-wrap: anywhere; }
#addAliasRowButton { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
dialog h2 { font-size: 20px; }
.result-name > span:first-child { min-width: 0; overflow-wrap: anywhere; }
button:disabled { opacity: 0.55; cursor: wait; }

.hand-count-button { width: auto; min-width: 54px; gap: 5px; padding: 0 8px; }
.attachment-fieldset { min-width: 0; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 6px; }
.attachment-fieldset legend { font-size: 13px; color: var(--muted); font-weight: 700; }
.attachment-fieldset input[type=file] { border: 0; padding: 6px 0; font-size: 12px; min-width: 0; }
.attachment-drafts { display: grid; gap: 8px; margin: 8px 0; }
.attachment-draft { display: grid; grid-template-columns: 64px minmax(0,1fr) 38px; gap: 6px; align-items: center; }
.attachment-draft img { width: 64px; height: 54px; object-fit: contain; background: #e6ecef; }
#pairMediaButton { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.note-images { margin-top: 10px; }
.note-images summary { color: var(--accent-strong); font-weight: 700; cursor: pointer; padding: 5px 0; }
.note-image-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; padding-top: 6px; }
.note-image-previews { display: flex; flex-wrap: wrap; gap: 6px; }
.note-image-button { width: 64px; height: 46px; min-width: 0; border: 1px solid var(--line); border-radius: 4px; background: #eef2f3; overflow: hidden; padding: 3px; font-size: 10px; color: var(--muted); }
.note-image-button img { width: 100%; height: 100%; object-fit: contain; }
.note-image-button[aria-pressed=true] { border-color: var(--accent); outline: 1px solid var(--accent); }
.note-card [hidden] { display: none !important; }
.note-header { display: flex; align-items: center; gap: 6px; justify-content: space-between; margin-bottom: 4px; }
.note-header-actions { display: flex; align-items: center; gap: 4px; }
.note-header .note-meta { margin: 0; font-size: 11px; }
.note-header .tool-button { width: 28px; min-height: 26px; padding: 0; background: transparent; color: var(--muted); }
.note-header .tool-button svg { width: 15px; height: 15px; }
.note-text.is-collapsed { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.note-expand { color: var(--accent-strong); background: transparent; padding: 4px 0; font-size: 12px; }
.note-inline-hand { margin-top: 6px; }
.inline-hand-toolbar { display: flex; align-items: center; gap: 5px; padding: 3px 0; font-size: 12px; }
.inline-hand-toolbar .tool-button { width: 30px; min-height: 28px; background: #e1e7ea; color: #172027; }
.inline-hand-toolbar > button:last-child { margin-left: auto; }
.inline-hand-preview { display: flex; align-items: center; justify-content: center; width: 100%; height: 220px; background: #e8ecee; padding: 5px; color: var(--muted); font-size: 12px; }
.inline-hand-preview img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.inline-hand-caption { margin-top: 4px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
dialog.hand-gallery { width: min(1100px, calc(100vw - 24px)); height: min(850px, 88dvh); background: #f4f6f7; }
.hand-gallery [hidden] { display: none !important; }
.gallery-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 12px; border-bottom: 1px solid #d5dde1; }
.gallery-header h2 { font-size: 18px; overflow-wrap: anywhere; }
.gallery-toolbar { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.gallery-tool { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex: 0 0 auto; color: #172027; background: #e1e7ea; border-radius: 6px; border: 0; }
.gallery-tool svg { width: 20px; height: 20px; }
.gallery-counter { min-width: 54px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.hand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 14px; }
.hand-tile { padding: 0; background: white; color: #172027; border: 1px solid #d5dde1; border-radius: 6px; overflow: hidden; text-align: left; min-width: 0; }
.hand-tile-preview { aspect-ratio: 4 / 3; background: #e6ecef; display: grid; place-items: center; font-size: 12px; padding: 5px; text-align: center; }
.hand-tile-preview img { width: 100%; height: 100%; max-height: 170px; object-fit: contain; }
.hand-tile-caption { padding: 9px; font-size: 13px; }
.hand-tile-caption strong { display: block; overflow-wrap: anywhere; }
.hand-tile-caption p { margin-top: 5px; height: 36px; line-height: 18px; overflow: hidden; overflow-wrap: anywhere; color: #66727c; }
.hand-viewer { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 30%); min-height: 300px; height: calc(100% - 76px); padding: 14px; }
.hand-stage { position: relative; background: #182027; min-height: 0; flex: 1 1 auto; display: flex; align-items: center; justify-content: center; overflow: auto; }
.hand-stage img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; flex: 0 0 auto; }
.hand-stage.zoomed { display: block; }
.hand-stage.zoomed img { max-width: none; max-height: none; }
.hand-load-status { color: #dde6eb; padding: 20px; font-size: 14px; }
.hand-load-status:empty { display: none; }
.hand-caption { min-height: 0; padding: 12px; overflow-y: auto; background: white; font-size: 14px; overflow-wrap: anywhere; }
.hand-caption p { margin-top: 5px; white-space: pre-wrap; line-height: 1.4; }
.hand-image-caption:empty { display: none; }
.hand-image-caption { color: var(--muted); }
.gallery-empty { padding: 30px; color: #66727c; grid-column: 1 / -1; text-align: center; }

@media (max-width: 600px) {
  .hand-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; }
  .hand-tile-preview img { max-height: 125px; }
  .gallery-header h2 { width: 100%; }
  .hand-viewer { display: flex; flex-direction: column; height: calc(100% - 116px); padding: 8px; }
  .hand-caption { flex: 0 0 auto; min-height: 100px; max-height: 180px; }
  .hand-tile-caption { font-size: 12px; padding: 7px; }
  .hand-gallery .gallery-tool { width: 34px; height: 34px; }
}

.small-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 10px;
  background: #25323b;
  color: white;
  font-weight: 700;
}

.labels,
.notes {
  display: grid;
  gap: 8px;
}

.section-title {
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.label-item,
.note-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.label-item {
  padding: 10px 12px;
  font-weight: 700;
}

.note-card {
  padding: 7px 10px;
}

.note-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.4;
  font-size: 14px;
}

.note-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.note-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.link-button {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

dialog {
  width: min(520px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(16, 24, 32, 0.45);
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

dialog header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

dialog label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

dialog input,
dialog select,
dialog textarea {
  min-height: 42px;
  padding: 9px 10px;
  color: var(--ink);
  font-weight: 400;
}

dialog textarea {
  resize: vertical;
}

.danger {
  background: var(--danger);
  color: white;
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand h1 {
    font-size: 19px;
  }

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

  .results-panel,
  .details-panel {
    min-height: auto;
  }

  .results-list {
    max-height: 38vh;
  }

  .details-panel {
    min-height: 42vh;
  }

  .search-row {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
  }

  #addButton {
    width: 42px;
  }

  #pasteButton { padding: 0 8px; font-size: 12px; }
  .details-head { flex-wrap: wrap; }
  .details-head h2 { font-size: 22px; }
}
.account-actions { display: flex; gap: 8px; flex-shrink: 0; }
.legacy-pair { margin-top: 18px; border-top: 1px solid #cbd5dc; padding-top: 12px; }
#accountStatus { overflow-wrap: anywhere; }
#mediaPairDialog [hidden] { display: none !important; }
.my-image-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.my-image-row img { width: 56px; height: 42px; object-fit: contain; }
.my-image-caption { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.my-image-caption input { width: 100%; min-width: 0; }
#myImagesList { max-height: 240px; overflow-y: auto; }
