:root {
  --bg: #f4f4f2;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --card: #ffffff;
  --border: #dcdbd5;
  --accent: #2f6fdb;
  --accent-fg: #ffffff;
  --danger: #c23a2b;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --fg: #ececea;
    --muted: #9a9a94;
    --card: #1f1f1d;
    --border: #34342f;
    --accent: #6a9cf0;
    --accent-fg: #0d1a30;
    --danger: #e36a5c;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { display: block; border-radius: 7px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); margin: 0; min-height: 1.5em; font-size: 14px; }

input, button {
  font: inherit;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; white-space: nowrap; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--fg); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* Kirjautuminen */
#login {
  width: min(360px, calc(100% - 32px));
  margin: 18vh auto 0;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#login h1 { margin-bottom: 4px; }

/* Sovellus */
main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 64px; }
header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
header #logout { margin-left: auto; }

#drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 36px 16px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
#drop strong { color: var(--fg); }
#drop:hover, #drop.over { border-color: var(--accent); color: var(--accent); }

#gallery {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}
#empty { text-align: center; margin-top: 32px; }

.tile {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
}
.tile .thumb { position: relative; display: block; aspect-ratio: 1; background: var(--bg); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Napit kuvan alla omassa palkissa */
.tile .actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
}
.tile .actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 6px 10px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tile .actions .icon { width: 36px; padding: 6px 0; }
.tile .actions svg { flex: none; }
.tile .actions .del { color: var(--danger); }
.tile .actions button.copied { background: #1f8a4c; border-color: #1f8a4c; color: #ffffff; }
/* Poiston varmistus: punainen nappi täyttää palkin */
.tile .actions.confirming .copy, .tile .actions.confirming .link { display: none; }
.tile .actions.confirming .del {
  grid-column: 1 / -1;
  width: auto;
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
  font-weight: 600;
}
.tile .actions .del:disabled { opacity: 0.7; cursor: default; }
/* Kapea ruutu (esim. puhelin): pääpainike omalle rivilleen */
@container (max-width: 230px) {
  .tile .actions { grid-template-columns: 1fr 1fr; }
  .tile .actions .copy { grid-column: 1 / -1; }
  .tile .actions .icon { width: auto; }
}

/* Lataus käynnissä */
.tile.uploading img { opacity: 0.45; }
.tile .progress {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 6px;
  border-radius: 3px;
  background: rgb(255 255 255 / 50%);
  overflow: hidden;
}
.tile .progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }
.tile.failed .thumb { display: flex; align-items: center; justify-content: center; padding: 12px; text-align: center; }
.tile.failed p { margin: 0; color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  #gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

/* Yksittäisen kuvan sivu */
body.view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
}
body.view img { max-width: 100vw; max-height: 100vh; display: block; }
