/*
Theme Name: Kodandam
Theme URI: https://kodandam.si
Author: Kodandam
Author URI: https://kodandam.si
Description: Kodandam (kodandam.si, "super intelligence") is an AI chat companion for the teachings of Lord Ram, Lord Krishna and the Hindu scriptures. Members sign in with Google, ask questions in their own language and get answers grounded in the Ramayana, Bhagavad Gita, Mahabharata, Puranas, Upanishads and Vedas, with references. Includes a scripture importer for free, public-domain texts and an admin screen for the AI model and Google sign-in.
Version: 1.3.0
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: kodandam
Tags: one-column, custom-logo, full-width-template, translation-ready
*/

/* ------------------------------------------------------------------ */
/* Tokens                                                              */
/* ------------------------------------------------------------------ */
:root {
	--kd-bg: #fbf7ef;
	--kd-sidebar: #f3ecdf;
	--kd-surface: #ffffff;
	--kd-surface-2: #f6f0e4;
	--kd-ink: #2b2118;
	--kd-ink-soft: #5b4a3a;
	--kd-muted: #8a7663;
	--kd-line: #e6dccb;
	--kd-brand: #5c3a1e;
	--kd-brand-hover: #4a2e17;
	--kd-on-brand: #fffaf1;
	--kd-accent: #b7793f;
	--kd-user-bubble: #efe5d3;
	--kd-danger: #a33a2a;
	--kd-shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .06);
	--kd-radius: 18px;
	--kd-font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
	--kd-font-read: "Inter", "Noto Serif Devanagari", system-ui, sans-serif;
	--kd-font-display: "Cormorant Garamond", "Noto Serif Devanagari", Georgia, serif;
	--kd-sidebar-w: 280px;
	--kd-thread-w: 760px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--kd-bg: #1b1713;
		--kd-sidebar: #15120f;
		--kd-surface: #24201b;
		--kd-surface-2: #2b261f;
		--kd-ink: #f1e8da;
		--kd-ink-soft: #d6c7b2;
		--kd-muted: #a3917b;
		--kd-line: #3a332a;
		--kd-brand: #d9b48a;
		--kd-brand-hover: #e8c79f;
		--kd-on-brand: #1b1713;
		--kd-accent: #d9a56b;
		--kd-user-bubble: #312a22;
		--kd-danger: #e3836f;
		--kd-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
	}
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--kd-bg);
	color: var(--kd-ink);
	font-family: var(--kd-font-ui);
	font-size: 16px;
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
}
a { color: var(--kd-brand); }
a:hover { color: var(--kd-brand-hover); }
img { max-width: 100%; height: auto; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--kd-accent); outline-offset: 2px; }
.screen-reader-text { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px); }

/* Logo artwork has a cream background: frame it as a tile in dark mode. */
@media (prefers-color-scheme: dark) {
	.kd-brand img, .kd-empty__mark, .kd-avatar--bot, .kd-login__logo { background: #fef8eb; }
}

.kd-icon-btn {
	display: inline-grid;
	place-items: center;
	width: 36px;
	height: 36px;
	border-radius: 10px;
	border: 0;
	background: transparent;
	color: var(--kd-ink-soft);
	cursor: pointer;
	text-decoration: none;
	flex: none;
}
.kd-icon-btn:hover { background: var(--kd-surface-2); color: var(--kd-ink); }

.kd-brand {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	text-decoration: none;
	color: var(--kd-ink);
	font-family: var(--kd-font-display);
	font-size: 24px;
	font-weight: 600;
	letter-spacing: .02em;
}
.kd-brand img { border-radius: 9px; }

.kd-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 9px 16px;
	border-radius: 999px;
	background: var(--kd-brand);
	color: var(--kd-on-brand);
	text-decoration: none;
	font-weight: 500;
	font-size: 14px;
}
.kd-btn:hover { background: var(--kd-brand-hover); color: var(--kd-on-brand); }

/* ------------------------------------------------------------------ */
/* Sign-in page                                                        */
/* ------------------------------------------------------------------ */
.kd-login {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 32px 16px 24px;
	background:
		radial-gradient(1200px 600px at 50% -10%, rgba(183, 121, 63, .10), transparent 60%),
		var(--kd-bg);
}
.kd-login__card {
	width: 100%;
	max-width: 440px;
	text-align: center;
}
.kd-login__logo {
	width: 220px;
	height: 220px;
	margin: 0 auto 4px;
	display: block;
	border-radius: 28px;
}
.kd-login__tagline {
	font-family: var(--kd-font-display);
	font-size: 24px;
	line-height: 1.3;
	color: var(--kd-ink-soft);
	margin: 0 0 28px;
}
.kd-google-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	width: 100%;
	padding: 14px 20px;
	border-radius: 14px;
	background: var(--kd-surface);
	border: 1px solid var(--kd-line);
	color: var(--kd-ink);
	text-decoration: none;
	font-weight: 500;
	box-shadow: var(--kd-shadow);
	transition: transform .15s ease, box-shadow .15s ease;
}
.kd-google-btn:hover { color: var(--kd-ink); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(60, 40, 20, .08), 0 12px 28px rgba(60, 40, 20, .10); }
.kd-login__points {
	list-style: none;
	padding: 0;
	margin: 28px 0 0;
	text-align: left;
	color: var(--kd-ink-soft);
	font-size: 15px;
}
.kd-login__points li {
	position: relative;
	padding: 6px 0 6px 28px;
}
.kd-login__points li::before {
	content: "";
	position: absolute;
	left: 4px;
	top: 15px;
	width: 10px;
	height: 2px;
	background: var(--kd-accent);
	box-shadow: 6px 0 0 var(--kd-accent);
	transform: rotate(-20deg);
}
.kd-login__legal { font-size: 12.5px; color: var(--kd-muted); margin-top: 28px; }
.kd-login__footer { margin-top: 32px; font-size: 13px; color: var(--kd-muted); text-align: center; }

.kd-alert {
	text-align: left;
	padding: 12px 14px;
	margin: 0 0 16px;
	border-radius: 12px;
	background: rgba(163, 58, 42, .08);
	border: 1px solid rgba(163, 58, 42, .25);
	color: var(--kd-danger);
	font-size: 14px;
}
.kd-alert--info {
	background: var(--kd-surface-2);
	border-color: var(--kd-line);
	color: var(--kd-ink-soft);
}

/* ------------------------------------------------------------------ */
/* App layout                                                          */
/* ------------------------------------------------------------------ */
.kd-app-body { overflow: hidden; }
.kd-app {
	display: flex;
	height: 100vh;
	height: 100dvh;
}

.kd-sidebar {
	width: var(--kd-sidebar-w);
	flex: none;
	display: flex;
	flex-direction: column;
	background: var(--kd-sidebar);
	border-right: 1px solid var(--kd-line);
	padding: 14px 10px 10px;
	min-height: 0;
}
.kd-sidebar__top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 2px 6px 14px;
}
.kd-new-chat {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 10px 12px;
	border-radius: 12px;
	border: 1px solid var(--kd-line);
	background: var(--kd-surface);
	cursor: pointer;
	font-weight: 500;
	font-size: 14.5px;
	color: var(--kd-ink);
	box-shadow: 0 1px 2px rgba(60, 40, 20, .05);
}
.kd-new-chat svg { color: var(--kd-brand); }
.kd-new-chat:hover { border-color: var(--kd-accent); }
.kd-sidebar__label {
	margin: 20px 10px 6px;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: var(--kd-muted);
}
.kd-conv-list {
	flex: 1;
	overflow-y: auto;
	min-height: 0;
	margin: 0 -4px;
	padding: 0 4px;
}
.kd-conv {
	display: flex;
	align-items: center;
	gap: 4px;
	border-radius: 10px;
}
.kd-conv a {
	flex: 1;
	min-width: 0;
	padding: 8px 10px;
	color: var(--kd-ink-soft);
	text-decoration: none;
	font-size: 14px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.kd-conv:hover { background: var(--kd-surface-2); }
.kd-conv.is-active { background: var(--kd-surface); box-shadow: 0 1px 2px rgba(60, 40, 20, .06); }
.kd-conv.is-active a { color: var(--kd-ink); font-weight: 500; }
.kd-conv .kd-icon-btn { width: 30px; height: 30px; opacity: 0; }
.kd-conv:hover .kd-icon-btn, .kd-conv.is-active .kd-icon-btn, .kd-conv .kd-icon-btn:focus-visible { opacity: 1; }
.kd-conv-empty { padding: 8px 10px; font-size: 13.5px; color: var(--kd-muted); }

.kd-user {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 6px 4px;
	border-top: 1px solid var(--kd-line);
	margin-top: 8px;
}
.kd-user__avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.kd-user__meta { flex: 1; min-width: 0; line-height: 1.3; }
.kd-user__name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kd-user__email { font-size: 12px; color: var(--kd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.kd-main {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	position: relative;
}
.kd-topbar {
	display: flex;
	align-items: center;
	gap: 8px;
	height: 56px;
	padding: 0 16px;
	flex: none;
}
.kd-topbar__title {
	font-size: 15px;
	font-weight: 500;
	color: var(--kd-ink-soft);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.kd-thread {
	flex: 1;
	overflow-y: auto;
	min-height: 0;
	padding: 8px 16px 24px;
	scroll-behavior: smooth;
}

/* Empty state */
.kd-empty {
	max-width: var(--kd-thread-w);
	margin: 0 auto;
	min-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 24px 0 40px;
}
.kd-empty[hidden] { display: none; }
.kd-empty__mark { width: 72px; height: 72px; border-radius: 18px; }
.kd-empty__greeting {
	font-family: var(--kd-font-display);
	font-weight: 500;
	font-size: clamp(30px, 4.5vw, 44px);
	line-height: 1.15;
	margin: 14px 0 28px;
	color: var(--kd-ink);
}
.kd-suggestions {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
	width: 100%;
	max-width: 680px;
}
.kd-suggestion {
	text-align: left;
	padding: 14px 16px;
	border-radius: 14px;
	border: 1px solid var(--kd-line);
	background: var(--kd-surface);
	cursor: pointer;
	color: var(--kd-ink-soft);
	font-size: 14.5px;
	line-height: 1.45;
	transition: border-color .15s ease, transform .15s ease;
}
.kd-suggestion strong { display: block; color: var(--kd-ink); font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.kd-suggestion:hover { border-color: var(--kd-accent); transform: translateY(-1px); }

/* Messages */
.kd-messages { max-width: var(--kd-thread-w); margin: 0 auto; }
.kd-msg { margin: 18px 0; }
.kd-msg--user { display: flex; justify-content: flex-end; }
.kd-msg--user .kd-bubble {
	max-width: 85%;
	background: var(--kd-user-bubble);
	padding: 10px 16px;
	border-radius: 18px 18px 6px 18px;
	white-space: pre-wrap;
	word-wrap: break-word;
}
.kd-msg--bot { display: flex; gap: 14px; align-items: flex-start; }
.kd-avatar--bot { width: 30px; height: 30px; border-radius: 8px; flex: none; margin-top: 2px; }
.kd-msg--bot .kd-body { flex: 1; min-width: 0; }
.kd-answer { font-family: var(--kd-font-read); font-size: 16px; line-height: 1.7; overflow-wrap: anywhere; }
.kd-answer > :first-child { margin-top: 0; }
.kd-answer > :last-child { margin-bottom: 0; }
.kd-answer p { margin: 0 0 .9em; }
.kd-answer h1, .kd-answer h2, .kd-answer h3, .kd-answer h4 {
	font-family: var(--kd-font-display);
	font-weight: 600;
	line-height: 1.25;
	margin: 1.2em 0 .45em;
}
.kd-answer h1 { font-size: 1.6em; }
.kd-answer h2 { font-size: 1.4em; }
.kd-answer h3, .kd-answer h4 { font-size: 1.2em; }
.kd-answer ul, .kd-answer ol { margin: 0 0 .9em; padding-left: 1.4em; }
.kd-answer li { margin: .25em 0; }
.kd-answer blockquote {
	margin: 1em 0;
	padding: .6em 1em;
	border-left: 3px solid var(--kd-accent);
	background: var(--kd-surface-2);
	border-radius: 0 10px 10px 0;
	font-family: "Noto Serif Devanagari", var(--kd-font-display);
	font-size: 1.04em;
}
.kd-answer code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: .9em;
	background: var(--kd-surface-2);
	padding: .1em .35em;
	border-radius: 5px;
}
.kd-answer pre {
	background: var(--kd-surface-2);
	border: 1px solid var(--kd-line);
	padding: 12px 14px;
	border-radius: 12px;
	overflow-x: auto;
}
.kd-answer pre code { background: none; padding: 0; }
.kd-answer hr { border: 0; border-top: 1px solid var(--kd-line); margin: 1.4em 0; }
.kd-answer strong { font-weight: 600; }

.kd-sources {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 12px;
}
.kd-source {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	max-width: 100%;
	padding: 5px 10px;
	border: 1px solid var(--kd-line);
	border-radius: 999px;
	background: var(--kd-surface);
	font-size: 12.5px;
	color: var(--kd-ink-soft);
	text-decoration: none;
}
.kd-source span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.kd-source:hover { border-color: var(--kd-accent); color: var(--kd-ink); }

.kd-actions { display: flex; gap: 2px; margin-top: 6px; margin-left: -8px; }
.kd-actions .kd-icon-btn { width: 32px; height: 32px; color: var(--kd-muted); }
.kd-actions .kd-icon-btn.is-done { color: var(--kd-accent); }

.kd-error {
	color: var(--kd-danger);
	background: rgba(163, 58, 42, .07);
	border: 1px solid rgba(163, 58, 42, .2);
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 14.5px;
}

/* Thinking indicator: three arrows in flight */
.kd-thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--kd-muted); font-size: 14.5px; padding-top: 4px; }
.kd-thinking__dots { display: inline-flex; gap: 5px; }
.kd-thinking__dots i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--kd-accent);
	animation: kd-pulse 1.2s infinite ease-in-out;
}
.kd-thinking__dots i:nth-child(2) { animation-delay: .15s; }
.kd-thinking__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes kd-pulse {
	0%, 80%, 100% { opacity: .25; transform: scale(.8); }
	40% { opacity: 1; transform: scale(1); }
}
.kd-reveal { animation: kd-fade .35s ease both; }
@keyframes kd-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Composer */
.kd-composer {
	flex: none;
	padding: 0 16px 10px;
	padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.kd-composer__box {
	max-width: var(--kd-thread-w);
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	gap: 4px;
	background: var(--kd-surface);
	border: 1px solid var(--kd-line);
	border-radius: 22px;
	padding: 12px 10px 10px 18px;
	box-shadow: var(--kd-shadow);
	transition: border-color .15s ease;
}
.kd-composer__box:focus-within { border-color: var(--kd-accent); }
.kd-composer__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-left: -8px; }
.kd-composer__tools { display: flex; align-items: center; gap: 6px; min-height: 36px; }
.kd-tool {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 34px;
	padding: 0 12px;
	border-radius: 999px;
	border: 1px solid var(--kd-line);
	background: transparent;
	color: var(--kd-ink-soft);
	font-size: 13.5px;
	cursor: pointer;
}
.kd-tool:hover { background: var(--kd-surface-2); color: var(--kd-ink); }
.kd-tool[aria-pressed="true"] { background: var(--kd-brand); border-color: var(--kd-brand); color: var(--kd-on-brand); }
.kd-aspect {
	height: 34px;
	border-radius: 999px;
	border: 1px solid var(--kd-line);
	background: var(--kd-surface);
	color: var(--kd-ink-soft);
	font: inherit;
	font-size: 13.5px;
	padding: 0 10px;
}
.kd-aspect[hidden] { display: none; }
.kd-gen-image {
	display: block;
	max-width: min(100%, 520px);
	border-radius: 14px;
	border: 1px solid var(--kd-line);
	margin: 10px 0 2px;
	background: var(--kd-surface-2);
}
.kd-image-skeleton {
	width: min(100%, 360px);
	aspect-ratio: 1 / 1;
	border-radius: 14px;
	margin-top: 10px;
	background: linear-gradient(110deg, var(--kd-surface-2) 30%, var(--kd-line) 50%, var(--kd-surface-2) 70%);
	background-size: 250% 100%;
	animation: kd-shimmer 1.6s linear infinite;
}
@keyframes kd-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.kd-composer textarea {
	flex: 1;
	border: 0;
	outline: 0;
	resize: none;
	background: transparent;
	color: var(--kd-ink);
	font: inherit;
	font-size: 16px;
	line-height: 1.5;
	max-height: 220px;
	padding: 2px 0 6px;
}
.kd-composer textarea::placeholder { color: var(--kd-muted); }
.kd-send {
	width: 38px;
	height: 38px;
	border-radius: 12px;
	border: 0;
	background: var(--kd-brand);
	color: var(--kd-on-brand);
	display: grid;
	place-items: center;
	cursor: pointer;
	flex: none;
	transition: background .15s ease, opacity .15s ease;
}
.kd-send:hover:not(:disabled) { background: var(--kd-brand-hover); }
.kd-send:disabled { opacity: .35; cursor: default; }
.kd-disclaimer { text-align: center; font-size: 12px; color: var(--kd-muted); margin: 8px 0 0; }

/* Site links (sign-in footer and sidebar) */
.kd-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin-bottom: 8px; }
.kd-links a { color: var(--kd-muted); text-decoration: none; font-size: 13px; }
.kd-links a:hover { color: var(--kd-ink); text-decoration: underline; }
.kd-links--sidebar { justify-content: flex-start; gap: 2px 12px; padding: 8px 10px 0; margin: 0; }
.kd-links--sidebar a { font-size: 12px; }

/* Mobile */
.kd-only-mobile { display: none; }
.kd-scrim { display: none; }
@media (max-width: 860px) {
	.kd-only-mobile { display: inline-grid; }
	.kd-sidebar {
		position: fixed;
		inset: 0 auto 0 0;
		z-index: 30;
		width: min(86vw, 320px);
		transform: translateX(-102%);
		transition: transform .22s ease;
		box-shadow: var(--kd-shadow);
	}
	.kd-app.is-nav-open .kd-sidebar { transform: none; }
	.kd-scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(20, 14, 8, .35); }
	.kd-scrim[hidden] { display: none; }
	.kd-suggestions { grid-template-columns: 1fr; }
	.kd-suggestion:nth-child(n+3) { display: none; }
	.kd-msg--bot { gap: 10px; }
	.kd-avatar--bot { width: 26px; height: 26px; }
	.kd-topbar { padding: 0 8px; }
}

/* ------------------------------------------------------------------ */
/* Regular pages (privacy, terms, posts)                               */
/* ------------------------------------------------------------------ */
.kd-site-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	max-width: 960px;
	margin: 0 auto;
	padding: 18px 16px;
}
.kd-page { max-width: 760px; margin: 0 auto; padding: 16px 16px 64px; }
.kd-article { margin-bottom: 48px; }
.kd-article__title {
	font-family: var(--kd-font-display);
	font-weight: 600;
	font-size: clamp(32px, 5vw, 44px);
	line-height: 1.15;
	margin: 16px 0 20px;
}
.kd-article__title a { color: inherit; text-decoration: none; }
.kd-article__content { font-size: 17px; line-height: 1.75; }
.kd-article__content h2, .kd-article__content h3 { font-family: var(--kd-font-display); font-weight: 600; }
.kd-table-wrap { overflow-x: auto; margin: 1.2em 0; }
.kd-sources-table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; }
.kd-sources-table th, .kd-sources-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--kd-line); vertical-align: top; }
.kd-sources-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--kd-muted); font-weight: 600; }
.kd-sources-table td:last-child { white-space: nowrap; color: var(--kd-ink-soft); }
.kd-article__content ul { padding-left: 1.3em; }
.kd-article__content li { margin: .3em 0; }
.kd-site-footer {
	text-align: center;
	color: var(--kd-muted);
	font-size: 13px;
	padding: 24px 16px 40px;
	border-top: 1px solid var(--kd-line);
}
.kd-footer-menu { list-style: none; padding: 0; margin: 0 0 8px; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.kd-footer-menu a { color: var(--kd-ink-soft); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
